ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-10-30 08:29:14
Exec Total Coverage
Lines: 3108 8717 35.7%
Functions: 84 304 27.6%
Branches: 2695 7701 35.0%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "base/zdefs.h"
12 #include "dialog/info.h"
13 #include "metadata/metadata.h"
14
15 #include "base/qrs.h"
16 #include "base/dmap.h"
17 #include "base/packfile.h"
18 #include "base/cpool.h"
19 #include "base/autocombo.h"
20 #include "base/gui.h"
21 #include "base/msgstr.h"
22 #include "zc/zelda.h"
23 #include "zq/zq_class.h"
24 #include "zq/zq_misc.h"
25 #include "zq/zquest.h"
26 #include "base/qst.h"
27 #include "base/colors.h"
28 #include "tiles.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "base/md5.h"
34 #include "hero_tiles.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include "iter.h"
48 #include <fmt/format.h>
49 #include <filesystem>
50
51 #ifdef __EMSCRIPTEN__
52 #include "base/emscripten_utils.h"
53 #endif
54
55 namespace fs = std::filesystem;
56
57 using namespace util;
58
59 extern uint8_t ViewLayer3BG, ViewLayer2BG;
60 extern int32_t LayerDitherBG, LayerDitherSz;
61 extern bool NoHighlightLayer0;
62
63 using std::string;
64 using std::pair;
65
66 #define COLOR_SOLID vc(4)
67 #define COLOR_SLOPE vc(13)
68 #define COLOR_LADDER vc(6)
69 //#define COLOR_EFFECT vc(10)
70
71 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
72 extern char msgbuf[MSG_NEW_SIZE*8];
73
74 extern string zScript;
75
76 12 zmap Map;
77 int32_t prv_mode=0;
78
79 bool save_warn=true;
80
81 int32_t COMBOPOS(int32_t x, int32_t y)
82 {
83 return (((y) & 0xF0) + ((x) >> 4));
84 }
85 int32_t COMBOPOS_B(int32_t x, int32_t y)
86 {
87 if(unsigned(x) >= 256 || unsigned(y) >= 176)
88 return -1;
89 return COMBOPOS(x,y);
90 }
91 int32_t COMBOX(int32_t pos)
92 {
93 return ((pos) % 16 * 16);
94 }
95 int32_t COMBOY(int32_t pos)
96 {
97 return ((pos) & 0xF0);
98 }
99
100 void reset_dmap(int32_t index)
101 {
102 bound(index,0,MAXDMAPS-1);
103 DMaps[index].clear();
104 DMaps[index].title = "";
105 sprintf(DMaps[index].intro, " ");
106 }
107
108 void reset_dmaps()
109 {
110 for(int32_t i=0; i<MAXDMAPS; i++)
111 reset_dmap(i);
112 }
113
114 void truncate_dmap_title(std::string& title)
115 {
116 title.resize(21, ' ');
117 }
118
119 mapscr* zmap::get_prvscr()
120 {
121 return &prvscr;
122 }
123
124
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
138 zmap::zmap()
125 {
126 23 can_paste=false;
127 23 prv_cmbcycle=0;
128 23 prv_advance=0;
129 23 prv_freeze=0;
130 23 copyffc=-1;
131
132 23 memset(scrpos, 0, sizeof(scrpos));
133 23 memset(scrview, 0, sizeof(scrview));
134 23 screens=NULL;
135 23 prv_time=0;
136 23 prv_scr=0;
137 23 prv_map=0;
138 23 copyscr=0;
139 23 cursor={};
140 copymap=0;
141 layer_target_map = 0;
142 layer_target_scr = 0;
143 layer_target_multiple = 0;
144 }
145
146 11 void zmap::clear()
147 {
148
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
149 11 }
150 void zmap::force_refr_pointer()
151 {
152 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
153 screens = nullptr;
154 else screens = &TheMaps[cursor.map*MAPSCRS];
155 }
156 bool zmap::CanUndo()
157 {
158 return undo_stack.size() > 0;
159 }
160 bool zmap::CanRedo()
161 {
162 return redo_stack.size() > 0;
163 }
164 bool zmap::CanPaste()
165 {
166 return can_paste;
167 }
168 int32_t zmap::CopyScr()
169 {
170 return (copymap<<8)+copyscr;
171 }
172 int32_t zmap::getCopyFFC()
173 {
174 return copyffc;
175 }
176 set_ffc_command::data_t zmap::getCopyFFCData()
177 {
178 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
179 }
180 46 int32_t zmap::getMapCount()
181 {
182 46 return map_count;
183 }
184 int32_t zmap::getLayerTargetMap()
185 {
186 return layer_target_map;
187 }
188 int32_t zmap::getLayerTargetScr()
189 {
190 return layer_target_scr;
191 }
192 int32_t zmap::getLayerTargetMultiple()
193 {
194 return layer_target_multiple;
195 }
196 bool zmap::isDungeon(int32_t scr)
197 {
198 for(int32_t i=0; i<4; i++)
199 {
200 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
201 {
202 return false;
203 }
204 }
205
206 return true;
207 }
208
209 bool zmap::clearall(bool validate)
210 {
211 Color=0;
212 char tbuf[10];
213
214 if((header.templatepath[0]!=0)&&validate)
215 {
216 if(!valid_zqt(header.templatepath))
217 {
218 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
219 return false;
220 }
221 }
222
223 for(int32_t i=0; i<map_count; i++)
224 {
225 setCurrMap(i);
226 sprintf(tbuf, "%d", i);
227 clearmap(true);
228 }
229
230 setCurrMap(0);
231 return true;
232 }
233
234 bool zmap::reset_templates(bool validate)
235 {
236 //why are we doing this?
237 if(colordata==NULL)
238 {
239 return false;
240 }
241
242 //int32_t ret;
243 word version, build, dummy, sversion=0;
244 byte dummyc;
245 word dummyw;
246 //int32_t section_size;
247 word temp_map_count;
248 mapscr temp_mapscr;
249 PACKFILE *f=NULL;
250
251 // setPackfilePassword(datapwd);
252 f=open_quest_template(&header, "modules/classic/default.qst", validate);
253 get_version_and_build(f, &version, &build);
254
255 if(!find_section(f, ID_MAPS))
256 {
257 // setPackfilePassword(NULL);
258 return false;
259 }
260
261 //section version info
262 if(!p_igetw(&sversion,f))
263 {
264 return false;
265 }
266
267 if(!p_igetw(&dummy,f))
268 {
269 return false;
270 }
271
272 //section size
273 dword dummy_size;
274 if(!p_igetl(&dummy_size,f))
275 {
276 return false;
277 }
278
279 //finally... section data
280 if(!p_igetw(&temp_map_count,f))
281 {
282 return false;
283 }
284
285 if(version>12)
286 {
287 if(!p_getc(&dummyc,f))
288 return qe_invalid;
289
290 if(!p_getc(&dummyc,f))
291 return qe_invalid;
292
293 if(!p_igetw(&dummyw,f))
294 return qe_invalid;
295
296 if(!p_igetw(&dummyw,f))
297 return qe_invalid;
298
299 if(!p_igetw(&dummyw,f))
300 return qe_invalid;
301
302 if(!p_igetw(&dummyw,f))
303 return qe_invalid;
304
305 if(!p_igetw(&dummyw,f))
306 return qe_invalid;
307
308 if(!p_igetw(&dummyw,f))
309 return qe_invalid;
310
311 if(!p_igetw(&dummyw,f))
312 return qe_invalid;
313
314 if(!p_igetw(&dummyw,f))
315 return qe_invalid;
316
317 if(!p_igetw(&dummyw,f))
318 return qe_invalid;
319
320 if(!p_igetw(&dummyw,f))
321 return qe_invalid;
322
323 if(!p_getc(&dummyc,f))
324 return qe_invalid;
325
326 if(!p_getc(&dummyc,f))
327 return qe_invalid;
328 }
329
330 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
331 {
332 readmapscreen(f, &header, &temp_mapscr, sversion);
333 }
334
335 readmapscreen(f, &header, &TheMaps[128], sversion);
336 readmapscreen(f, &header, &TheMaps[129], sversion);
337
338 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
339 {
340 readmapscreen(f, &header, &temp_mapscr, sversion);
341 }
342
343 if(version>12)
344 {
345 if(!p_getc(&dummyc,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_igetw(&dummyw,f))
352 return qe_invalid;
353
354 if(!p_igetw(&dummyw,f))
355 return qe_invalid;
356
357 if(!p_igetw(&dummyw,f))
358 return qe_invalid;
359
360 if(!p_igetw(&dummyw,f))
361 return qe_invalid;
362
363 if(!p_igetw(&dummyw,f))
364 return qe_invalid;
365
366 if(!p_igetw(&dummyw,f))
367 return qe_invalid;
368
369 if(!p_igetw(&dummyw,f))
370 return qe_invalid;
371
372 if(!p_igetw(&dummyw,f))
373 return qe_invalid;
374
375 if(!p_igetw(&dummyw,f))
376 return qe_invalid;
377
378 if(!p_igetw(&dummyw,f))
379 return qe_invalid;
380
381 if(!p_getc(&dummyc,f))
382 return qe_invalid;
383
384 if(!p_getc(&dummyc,f))
385 return qe_invalid;
386 }
387
388 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
389 {
390 readmapscreen(f, &header, &temp_mapscr, sversion);
391 }
392
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
394 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
395
396 pack_fclose(f);
397 clear_quest_tmpfile();
398
399 return true;
400 }
401
402 bool zmap::clearmap(bool newquest)
403 {
404 if(cursor.map<map_count)
405 {
406 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
407 {
408 clearscr(i);
409 }
410
411 setCurrScr(0);
412
413 if(newquest)
414 {
415 if(!reset_templates(false))
416 {
417 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
418 }
419 }
420 }
421
422 return true;
423 }
424
425 MapCursor zmap::getCursor() const
426 {
427 return cursor;
428 }
429
430 void zmap::setCursor(MapCursor new_cursor)
431 {
432 if (cursor == new_cursor)
433 return;
434
435 if (!screens) Color = -1;
436
437 cursor = new_cursor;
438
439 refresh_color();
440
441 reset_combo_animations2();
442 mmap_mark_dirty();
443 regions_mark_dirty();
444 refresh(rALL);
445 }
446
447 bool zmap::isValidPosition(ComboPosition pos) const
448 {
449 return pos.is_valid(cursor);
450 }
451
452 int zmap::getScreenForPosition(ComboPosition pos) const
453 {
454 return cursor.viewscr + pos.screen_offset();
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+cursor.screen;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::Scr(ComboPosition pos)
466 {
467 if (!pos.is_valid(cursor))
468 return nullptr;
469
470 int screen_offset = pos.screen_offset();
471 int screen = cursor.viewscr + screen_offset;
472 return AbsoluteScr(cursor.map, screen);
473 }
474 mapscr* zmap::Scr(ComboPosition pos, int layer)
475 {
476 int map = cursor.map;
477 int screen = cursor.viewscr + pos.screen_offset();
478 if (layer)
479 {
480 mapscr* scr = Map.AbsoluteScr(map, screen);
481 map = scr->layermap[CurrentLayer-1]-1;
482 screen = scr->layerscreen[CurrentLayer-1];
483 }
484
485 return AbsoluteScr(map, screen);
486 }
487 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
488 {
489 mapscr* scr = Scr(pos, layer);
490 if (scr && !(scr->valid&mVALID))
491 {
492 scr->valid |= mVALID;
493 setcolor(Color, scr);
494 }
495 return scr;
496 }
497 mapscr* zmap::AbsoluteScr(int32_t scr)
498 {
499 if(unsigned(scr) >= MAPSCRS*getMapCount())
500 return nullptr;
501 return &TheMaps[scr];
502 }
503 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
504 {
505 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
506 return nullptr;
507 return AbsoluteScr((map*MAPSCRS)+scr);
508 }
509 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
510 {
511 mapscr* scr = AbsoluteScr(map, screen);
512 if (scr && !(scr->valid&mVALID))
513 {
514 scr->valid |= mVALID;
515 setcolor(Color, scr);
516 }
517 return scr;
518 }
519 void zmap::set_prvscr(int32_t map, int32_t scr)
520 {
521 prvscr = *get_canonical_scr(map, scr);
522
523 for(int32_t i=0; i<6; i++)
524 {
525 if(prvscr.layermap[i]>0)
526 {
527 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
528 }
529 else
530 prvlayers[i].valid = 0;
531 }
532
533 prv_map=map;
534 prv_scr=scr;
535 }
536 92 int32_t zmap::getCurrMap()
537 {
538 92 return cursor.map;
539 }
540 21 void zmap::regions_mark_dirty()
541 {
542 21 regions_dirty = true;
543 21 }
544 void zmap::regions_refresh()
545 {
546 if (!regions_dirty)
547 return;
548
549 regions_dirty = false;
550 region_descriptions.clear();
551
552 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
553 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
554 region_descriptions.clear();
555 }
556 const std::vector<region_description>& zmap::get_region_descriptions()
557 {
558 regions_refresh();
559 return region_descriptions;
560 }
561 bool zmap::is_region(int screen)
562 {
563 if (screen < 0 || screen >= 128)
564 return false;
565
566 regions_refresh();
567 return current_map_region_ids[screen];
568 }
569 bool zmap::isDark(int scr)
570 {
571 return (screens[scr].flags&fDARK)!=0;
572 }
573 bool zmap::isValid(int32_t scr)
574 {
575 return (screens[scr].valid&mVALID)!=0;
576 }
577 bool zmap::isValid(int32_t map, int32_t scr)
578 {
579 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
580 }
581
582 11 void zmap::setCurrMap(int32_t index)
583 {
584
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
585 11 scrpos[cursor.map] = cursor.screen;
586 11 scrview[cursor.map] = cursor.viewscr;
587 11 cursor.map = bound(index,0,map_count);
588 11 screens = &TheMaps[cursor.map*MAPSCRS];
589
590 11 cursor.viewscr = scrview[cursor.map];
591 11 cursor.setScreen(scrpos[cursor.map]);
592
593 11 refresh_color();
594
595 11 reset_combo_animations2();
596 11 mmap_mark_dirty();
597 11 regions_mark_dirty();
598 11 }
599
600 20 int32_t zmap::getCurrScr()
601 {
602 20 return cursor.screen;
603 }
604 11 void zmap::setCurrScr(int32_t scr)
605 {
606
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (scr == cursor.screen)
607 1 return;
608
609 10 cursor.setScreen(scr);
610
611 10 refresh_color();
612
613 10 reset_combo_animations2();
614 10 setlayertarget();
615 10 mmap_mark_dirty();
616 10 regions_mark_dirty();
617 11 }
618
619 int32_t zmap::getViewScr()
620 {
621 return cursor.viewscr;
622 }
623
624 11 void zmap::setViewSize(int32_t size)
625 {
626 11 cursor.setSize(size);
627 11 }
628
629 8 int32_t zmap::getViewSize()
630 {
631 8 return cursor.size;
632 }
633
634 10 void zmap::setlayertarget()
635 {
636 10 layer_target_map = 0;
637 10 layer_target_multiple = 0;
638
639
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 10 times.
46 for(int32_t m=0; m<getMapCount(); ++m)
640 {
641
2/2
✓ Branch 0 taken 4896 times.
✓ Branch 1 taken 36 times.
4932 for(int32_t s=0; s<MAPSCRS; ++s)
642 {
643 4896 int32_t i=(m*MAPSCRS+s);
644 4896 mapscr *ts=&TheMaps[i];
645
646 // Search through each layer
647
2/2
✓ Branch 0 taken 29376 times.
✓ Branch 1 taken 4896 times.
34272 for(int32_t w=0; w<6; ++w)
648 {
649
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 29365 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
29376 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
650 {
651 if(layer_target_map > 0)
652 {
653 layer_target_multiple += 1;
654 continue;
655 }
656
657 layer_target_map = m+1;
658 layer_target_scr = s;
659 }
660 29376 }
661 4896 }
662 36 }
663 10 }
664
665 21 void zmap::refresh_color()
666 {
667 21 auto color = getcolor();
668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (Color != color)
669 {
670 21 loadlvlpal(color);
671 21 rebuild_trans_table();
672 21 }
673 21 }
674
675 void zmap::setcolor(int color, mapscr* scr)
676 {
677 if (!scr)
678 scr = CurrScr();
679 scr->valid |= mVALID;
680 scr->color = color;
681
682 refresh_color();
683
684 mmap_mark_dirty();
685 }
686
687 21 int32_t zmap::getcolor()
688 {
689
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 mapscr& scr = prv_mode ? prvscr : screens[cursor.screen];
690
691
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
21 if (scr.valid & mVALID)
692 18 return scr.color;
693
694 3 return map_infos[cursor.map].autopalette;
695 21 }
696
697 void zmap::resetflags()
698 {
699 byte *di=&(screens[cursor.screen].valid);
700
701 for(int32_t i=1; i<48; i++)
702 {
703 *(di+i)=0;
704 }
705 }
706
707 word zmap::tcmbdat(int32_t pos)
708 {
709 return screens[TEMPLATE].data[pos];
710 }
711
712 word zmap::tcmbcset(int32_t pos)
713 {
714 return screens[TEMPLATE].cset[pos];
715 }
716
717 int32_t zmap::tcmbflag(int32_t pos)
718 {
719 return screens[TEMPLATE].sflag[pos];
720 }
721
722 word zmap::tcmbdat2(int32_t pos)
723 {
724 return screens[TEMPLATE2].data[pos];
725 }
726
727 word zmap::tcmbcset2(int32_t pos)
728 {
729 return screens[TEMPLATE2].cset[pos];
730 }
731
732 int32_t zmap::tcmbflag2(int32_t pos)
733 {
734 return screens[TEMPLATE2].sflag[pos];
735 }
736
737 void zmap::TemplateAll()
738 {
739 StartListCommand();
740 for(int32_t i=0; i<128; i++)
741 {
742 if((screens[i].valid&mVALID) && isDungeon(i))
743 DoTemplateCommand(-1, -1, i);
744 }
745 FinishListCommand();
746 }
747
748 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
749 {
750 if(scr==TEMPLATE)
751 return;
752
753 if(!(screens[scr].valid&mVALID))
754 screens[scr].color=Color;
755
756 screens[scr].valid|=mVALID;
757
758 for(int32_t i=0; i<32; i++)
759 {
760 screens[scr].data[i]=screens[TEMPLATE].data[i];
761 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
762 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
763 }
764
765 for(int32_t i=144; i<176; i++)
766 {
767 screens[scr].data[i]=screens[TEMPLATE].data[i];
768 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
769 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
770 }
771
772 for(int32_t y=2; y<=9; y++)
773 {
774 int32_t j=y<<4;
775 screens[scr].data[j]=screens[TEMPLATE].data[j];
776 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
777 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
778 ++j;
779 screens[scr].data[j]=screens[TEMPLATE].data[j];
780 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
781 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
782 ++j;
783 j+=12;
784 screens[scr].data[j]=screens[TEMPLATE].data[j];
785 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
786 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
787 ++j;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790
791 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
792 ++j;
793 }
794
795 if(floorcombo!=-1)
796 {
797 for(int32_t y=2; y<9; y++)
798 for(int32_t x=2; x<14; x++)
799 {
800 int32_t i=(y<<4)+x;
801 screens[scr].data[i] = floorcombo;
802 screens[scr].cset[i] = floorcset;
803 }
804 }
805
806 for(int32_t i=0; i<4; i++)
807 putdoor(scr,i,screens[scr].door[i]);
808 }
809
810
811 void zmap::clearscr(int32_t scr)
812 {
813 screens[scr].zero_memory();
814 screens[scr].valid=mVERSION;
815 auto const& mapinf = map_infos[cursor.map];
816 for(int q = 0; q < 6; ++q)
817 {
818 auto layer = mapinf.autolayers[q];
819 screens[scr].layermap[q] = layer;
820 screens[scr].layerscreen[q] = layer ? scr : 0;
821 }
822 screens[scr].color = mapinf.autopalette;
823 if (scr == cursor.screen)
824 refresh_color();
825 mmap_mark_dirty();
826 }
827
828 const char *loaderror[] =
829 {
830
831 "OK","File not found","Incomplete data",
832 "Invalid version","Invalid file"
833
834 };
835
836 int32_t zmap::load(const char *path)
837 {
838 PACKFILE *f=pack_fopen_password(path,F_READ, "");
839
840 if(!f)
841 return 1;
842
843
844 int16_t version;
845 byte build;
846
847 //get the version
848 if(!p_igetw(&version,f))
849 {
850 goto file_error;
851 }
852
853 //get the build
854 if(!p_getc(&build,f))
855 {
856 goto file_error;
857 }
858
859 for(int32_t i=0; i<MAPSCRS; i++)
860 {
861 mapscr tmpimportscr;
862 tmpimportscr.zero_memory();
863 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
864 {
865 al_trace("failed zmap::load\n");
866 goto file_error;
867 }
868
869 switch(ImportMapBias)
870 {
871 case 0:
872 *(screens+i) = tmpimportscr;
873 break;
874
875 case 1:
876 if(!(screens[i].valid&mVALID))
877 {
878 *(screens+i) = tmpimportscr;
879 }
880 break;
881
882 case 2:
883 if(tmpimportscr.valid&mVALID)
884 {
885 *(screens+i) = tmpimportscr;
886 }
887 break;
888 }
889 }
890
891
892 pack_fclose(f);
893
894 setCurrScr(0);
895 mmap_mark_dirty();
896 regions_mark_dirty();
897 return 0;
898
899 file_error:
900 pack_fclose(f);
901 clearmap(false);
902 return 2;
903 }
904
905 int32_t zmap::save(const char *path)
906 {
907 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
908
909 if(!f)
910 return 1;
911
912 if(!p_iputw(V_MAPS,f))
913 {
914 pack_fclose(f);
915 return 3;
916 }
917
918 // This was the "build number", but that's totally useless here. Keep this junk byte
919 // so as not to totally break exports between ZC versions.
920 if(!p_putc(0,f))
921 {
922 pack_fclose(f);
923 return 3;
924 }
925
926 for(int32_t i=0; i<MAPSCRS; i++)
927 {
928 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
929 {
930 pack_fclose(f);
931 return 2;
932 }
933 }
934
935 pack_fclose(f);
936 return 0;
937 }
938
939
940 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
941 {
942 // Hookshots can be blocked by solid combos on all 3 ground layers.
943 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
944
945 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
946 return true;
947 if (c->walk&(1<<i))
948 return false;
949
950 for(int32_t k=0; k<2; k++)
951 {
952 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
953
954 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
955 {
956 return false;
957 }
958 }
959
960 return true;
961 }
962
963 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
964 {
965 // Hookshots can be blocked by solid combos on all 3 ground layers.
966 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
967
968 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
969 return true;
970 if (c->walk&(1<<i))
971 return false;
972
973 for(int32_t k=0; k<2; k++)
974 {
975 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
976
977 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
978 {
979 return false;
980 }
981 }
982
983 return true;
984 }
985
986 bool zmap::isstepable(int32_t combo)
987 {
988 // This is kind of odd but it's true to the engine (see maps.cpp)
989 return (combo_class_buf[combobuf[combo].type].ladder_pass);
990 }
991
992 // Returns the letter of the warp combo.
993 int32_t zmap::warpindex(int32_t combo)
994 {
995 switch(combobuf[combo].type)
996 {
997 case cCAVE:
998 case cPIT:
999 case cSTAIR:
1000 case cCAVE2:
1001 case cSWIMWARP:
1002 case cDIVEWARP:
1003 case cSWARPA:
1004 return 0;
1005
1006 case cCAVEB:
1007 case cPITB:
1008 case cSTAIRB:
1009 case cCAVE2B:
1010 case cSWIMWARPB:
1011 case cDIVEWARPB:
1012 case cSWARPB:
1013 return 1;
1014
1015 case cCAVEC:
1016 case cPITC:
1017 case cSTAIRC:
1018 case cCAVE2C:
1019 case cSWIMWARPC:
1020 case cDIVEWARPC:
1021 case cSWARPC:
1022 return 2;
1023
1024 case cCAVED:
1025 case cPITD:
1026 case cSTAIRD:
1027 case cCAVE2D:
1028 case cSWIMWARPD:
1029 case cDIVEWARPD:
1030 case cSWARPD:
1031 return 3;
1032
1033 case cPITR:
1034 case cSTAIRR:
1035 case cSWARPR:
1036 return 4;
1037 }
1038
1039 return -1;
1040
1041 }
1042
1043 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1044 {
1045 if(top)
1046 line(dest,x,y,x+15,y,c);
1047 rectfill(dest,x,y,x+3,y+15,c);
1048 rectfill(dest,x+12,y,x+15,y+15,c);
1049 rectfill(dest,x+4,y+2,x+11,y+5,c);
1050 rectfill(dest,x+4,y+10,x+11,y+13,c);
1051 }
1052
1053 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1054 {
1055 line(dest,x,y,x+15,y,c);
1056 }
1057
1058 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1059 {
1060 int32_t cx = COMBOX(pos);
1061 int32_t cy = COMBOY(pos);
1062
1063 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1064
1065 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1066
1067 int32_t bridgedetected = 0;
1068
1069 for(int32_t i=0; i<4; i++)
1070 {
1071 int32_t tx=((i&2)<<2)+x;
1072 int32_t ty=((i&1)<<3)+y;
1073 int32_t tx2=((i&2)<<2)+cx;
1074 int32_t ty2=((i&1)<<3)+cy;
1075 for (int32_t m = layer; m <= 1; m++)
1076 {
1077 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1078 {
1079 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1080 {
1081 bridgedetected |= (1<<i);
1082 }
1083 }
1084 else
1085 {
1086 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1087 {
1088 bridgedetected |= (1<<i);
1089 }
1090 }
1091 }
1092 if (bridgedetected & (1<<i))
1093 {
1094 if (i >= 3) break;
1095 else continue;
1096 }
1097 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1098 {
1099 for(int32_t k=0; k<8; k+=2)
1100 for(int32_t j=0; j<8; j+=2)
1101 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1102 }
1103 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1104 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1105
1106 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1107 {
1108 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1109 {
1110 for(int32_t k=0; k<8; k+=2)
1111 for(int32_t j=0; j<8; j+=2)
1112 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1113 }
1114 else
1115 {
1116 int32_t color = COLOR_SOLID;
1117
1118 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1119 color=vc(6);
1120 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1121 color=vc(7);
1122
1123 rectfill(dest,tx,ty,tx+7,ty+7,color);
1124 }
1125 }
1126 }
1127
1128 bridgedetected = 0;
1129 for(int32_t i=0; i<4; i++)
1130 {
1131 int32_t tx2=((i&2)<<2)+cx;
1132 int32_t ty2=((i&1)<<3)+cy;
1133 for (int32_t m = 0; m <= 1; m++)
1134 {
1135 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1136 {
1137 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1138 {
1139 bridgedetected |= (1<<i);
1140 }
1141 }
1142 else
1143 {
1144 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1145 {
1146 bridgedetected |= (1<<i);
1147 }
1148 }
1149 }
1150 }
1151
1152 // Draw damage combos
1153 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1154 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1155 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1156 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1157 || combo_class_buf[c1.type].modify_hp_amount
1158 || combo_class_buf[c2.type].modify_hp_amount;
1159
1160 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1161
1162 if(dmg)
1163 {
1164 if (bridgedetected <= 0)
1165 {
1166 for(int32_t k=0; k<16; k+=2)
1167 for(int32_t j=0; j<16; j+=2)
1168 if(((k+j)/2)%2)
1169 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1170 }
1171 else
1172 {
1173 for(int32_t i=0; i<4; i++)
1174 {
1175 if (!(bridgedetected & (1<<i)))
1176 {
1177 int32_t tx=((i&2)<<2)+x;
1178 int32_t ty=((i&1)<<3)+y;
1179 for(int32_t k=0; k<8; k+=2)
1180 for(int32_t j=0; j<8; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1183 }
1184 }
1185 }
1186 }
1187
1188 if(c.type == cSLOPE)
1189 {
1190 slope_info s(c, x, y);
1191 s.draw(dest, 0, 0, COLOR_SLOPE);
1192 }
1193 auto fl0 = MAPFLAG2(-1,cx,cy);
1194 auto fl1 = MAPFLAG2(0,cx,cy);
1195 auto fl2 = MAPFLAG2(1,cx,cy);
1196 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1197 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1198 {
1199 bool top = false;
1200 if(cy)
1201 {
1202 top = true;
1203 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1204 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1205 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1206 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1207 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1208 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1209 {
1210 top = false;
1211 }
1212 }
1213 draw_ladder(dest,x,y,COLOR_LADDER,top);
1214 }
1215 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1216 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1217 {
1218 draw_platform(dest,x,y,COLOR_LADDER);
1219 }
1220 }
1221
1222 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1223 {
1224 int32_t cx = COMBOX(pos);
1225 int32_t cy = COMBOY(pos);
1226
1227 if (screen < 0) return;
1228 if (map < 0) return;
1229
1230 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1231
1232 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1233
1234 int32_t bridgedetected = 0;
1235 for(int32_t i=0; i<4; i++)
1236 {
1237 int32_t tx=((i&2)<<2)+x;
1238 int32_t ty=((i&1)<<3)+y;
1239 int32_t tx2=((i&2)<<2)+cx;
1240 int32_t ty2=((i&1)<<3)+cy;
1241 for (int32_t m = layer; m <= 1; m++)
1242 {
1243 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1244 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1245 {
1246 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1247 {
1248 bridgedetected |= (1<<i);
1249 }
1250 }
1251 else
1252 {
1253 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1254 {
1255 bridgedetected |= (1<<i);
1256 }
1257 }
1258 }
1259 if (bridgedetected & (1<<i))
1260 {
1261 continue;
1262 }
1263 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1264 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1265
1266
1267 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1268 {
1269 for(int32_t k=0; k<8; k+=2)
1270 for(int32_t j=0; j<8; j+=2)
1271 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1272 }
1273 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1274 {
1275 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1276 {
1277 for(int32_t k=0; k<8; k+=2)
1278 for(int32_t j=0; j<8; j+=2)
1279 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1280 }
1281 else
1282 {
1283 int32_t color = COLOR_SOLID;
1284
1285 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1286 color=vc(6);
1287 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1288 color=vc(7);
1289
1290 rectfill(dest,tx,ty,tx+7,ty+7,color);
1291 }
1292 }
1293 }
1294
1295 bridgedetected = 0;
1296 for(int32_t i=0; i<4; i++)
1297 {
1298 int32_t tx2=((i&2)<<2)+cx;
1299 int32_t ty2=((i&1)<<3)+cy;
1300 for (int32_t m = 0; m <= 1; m++)
1301 {
1302 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1303 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1304 {
1305 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1306 {
1307 bridgedetected |= (1<<i);
1308 }
1309 }
1310 else
1311 {
1312 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1313 {
1314 bridgedetected |= (1<<i);
1315 }
1316 }
1317 }
1318 }
1319
1320 // Draw damage combos
1321 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1322 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1323 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1324 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1325 || combo_class_buf[c1.type].modify_hp_amount
1326 || combo_class_buf[c2.type].modify_hp_amount;
1327
1328 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1329
1330 if(dmg)
1331 {
1332 if (bridgedetected <= 0)
1333 {
1334 for(int32_t k=0; k<16; k+=2)
1335 for(int32_t j=0; j<16; j+=2)
1336 if(((k+j)/2)%2)
1337 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1338 }
1339 else
1340 {
1341 for(int32_t i=0; i<4; i++)
1342 {
1343 if (!(bridgedetected & (1<<i)))
1344 {
1345 int32_t tx=((i&2)<<2)+x;
1346 int32_t ty=((i&1)<<3)+y;
1347 for(int32_t k=0; k<8; k+=2)
1348 for(int32_t j=0; j<8; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1351 }
1352 }
1353 }
1354 }
1355
1356 if(c.type == cSLOPE)
1357 {
1358 slope_info s(c, x, y);
1359 s.draw(dest, 0, 0, COLOR_SLOPE);
1360 }
1361 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1362 auto fl1 = MAPFLAG3(map,screen,0,pos);
1363 auto fl2 = MAPFLAG3(map,screen,1,pos);
1364 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1365 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1366 {
1367 bool top = false;
1368 if(cy)
1369 {
1370 top = true;
1371 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1372 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1373 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1374 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1375 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1376 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1377 {
1378 top = false;
1379 }
1380 }
1381 draw_ladder(dest,x,y,COLOR_LADDER,top);
1382 }
1383 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1384 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1385 {
1386 draw_platform(dest,x,y,COLOR_LADDER);
1387 }
1388 }
1389
1390 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1391 {
1392 const newcombo& c = combobuf[cmbdat];
1393
1394 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1395
1396 for(int32_t i=0; i<4; i++)
1397 {
1398 int32_t tx=((i&2)<<2)+x;
1399 int32_t ty=((i&1)<<3)+y;
1400
1401 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1402 {
1403 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1404 {
1405 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1406 }
1407 else
1408 {
1409 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1410 }
1411 }
1412
1413
1414 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1415 {
1416 for(int32_t k=0; k<8; k+=2)
1417 for(int32_t j=0; j<8; j+=2)
1418 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1419 }
1420 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1421 {
1422 if(c.type==cLADDERHOOKSHOT)
1423 {
1424 for(int32_t k=0; k<8; k+=2)
1425 for(int32_t j=0; j<8; j+=2)
1426 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1427 }
1428 else
1429 {
1430 int32_t color = COLOR_SOLID;
1431
1432 if(c.type==cLADDERONLY)
1433 color=vc(6);
1434 else if(c.type==cHOOKSHOTONLY)
1435 color=vc(7);
1436
1437 rectfill(dest,tx,ty,tx+7,ty+7,color);
1438 }
1439 }
1440
1441 // Draw damage combos
1442 if(combo_class_buf[c.type].modify_hp_amount != 0)
1443 {
1444 for(int32_t k=0; k<8; k+=2)
1445 for(int32_t j=0; j<8; j+=2)
1446 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1447 }
1448 }
1449
1450 if(c.type == cSLOPE)
1451 {
1452 slope_info s(c, 0, 0);
1453 zfix const& slope = s.slope();
1454
1455 BITMAP* sub = create_bitmap_ex(8,16,16);
1456 clear_bitmap(sub);
1457 s.draw(sub, 0, 0, COLOR_SLOPE);
1458 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1459 destroy_bitmap(sub);
1460 }
1461 if(c.flag == mfSIDEVIEWLADDER)
1462 {
1463 draw_ladder(dest,x,y,COLOR_LADDER);
1464 }
1465 else if(c.flag == mfSIDEVIEWPLATFORM)
1466 {
1467 draw_platform(dest,x,y,COLOR_LADDER);
1468 }
1469 }
1470
1471 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1472 {
1473 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1474 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1475 }
1476 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1477 {
1478
1479 newcombo const& c = combobuf[cmbdat];
1480
1481 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1482 {
1483 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1484 // text_mode(-1);
1485 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1486 if(sflag)
1487 {
1488 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1489 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1490 }
1491
1492 if(c.flag)
1493 {
1494 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1495 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1496 }
1497 }
1498
1499 if(flags&cCSET)
1500 {
1501 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1502 // text_mode(inv?vc(15):vc(0));
1503 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1504 }
1505 else if(flags&cCTYPE)
1506 {
1507 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1508 // text_mode(inv?vc(15):vc(0));
1509 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1510 }
1511 }
1512
1513 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1514 {
1515 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1516
1517 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1518 if(repos)
1519 {
1520 combotile_override_x = x+(8*(scale-1));
1521 combotile_override_y = y+(8*(scale-1));
1522 }
1523 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1524 if(repos) combotile_override_x = combotile_override_y = -1;
1525 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1526 destroy_bitmap(b);
1527 }
1528 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1529 {
1530 static newcombo nilcombo;
1531 nilcombo.tile = 0;
1532
1533 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1534
1535 if(c.tile==0)
1536 {
1537 rectfill(dest,x,y,x+15,y+15,vc(0));
1538 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1539 return;
1540 }
1541
1542 putcombo(dest,x,y,cmbdat,cset);
1543
1544 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1545 {
1546 if(sflag)
1547 {
1548 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1549 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1550 }
1551
1552 if(combobuf[cmbdat].flag)
1553 {
1554 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1555 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1556 }
1557 }
1558
1559 if(flags&cWALK)
1560 {
1561 put_walkflags(dest,x,y,cmbdat,0);
1562 }
1563
1564 if(flags&cCSET)
1565 {
1566 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1567 // text_mode(inv?vc(15):vc(0));
1568 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1569 }
1570 else if(flags&cCTYPE)
1571 {
1572 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1573 // text_mode(inv?vc(15):vc(0));
1574 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1575 }
1576 }
1577 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1578 {
1579 auto blitx = 1 + (slot % 16) * 17;
1580 auto blity = 1 + (slot / 16) * 17;
1581 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1582 }
1583
1584
1585 void copy_mapscr(mapscr *dest, const mapscr *src)
1586 {
1587 if(!dest || !src) return;
1588 *dest = *src;
1589 }
1590
1591 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1592 {
1593 int32_t x=0,y=0;
1594 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1595
1596 switch(side)
1597 {
1598 case up:
1599 case down:
1600 x=((pos&15)<<4)+xofs;
1601 y=(ignorepos?0:(pos&0xF0))+yofs;
1602 break;
1603
1604 case left:
1605 case right:
1606 x=(ignorepos?0:((pos&15)<<4))+xofs;
1607 y=(pos&0xF0)+yofs;
1608 break;
1609 }
1610
1611 switch(type)
1612 {
1613 case dt_lock:
1614 case dt_shut:
1615 case dt_boss:
1616 case dt_bomb:
1617 switch(side)
1618 {
1619 case up:
1620 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1621 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1622 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1623 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1624 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1625 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1626 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1627 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1628 break;
1629
1630 case down:
1631 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1633 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1635 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1637 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1638 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1639 break;
1640
1641 case left:
1642 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1646 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1648
1649 if(x+16 >= dest->w)
1650 break;
1651
1652 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1653 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1654 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1655 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1656 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1657 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1658 break;
1659
1660 case right:
1661
1662 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1663 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1664 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1665 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1666 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1667 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1668
1669 if(x+16 <= 0)
1670 break;
1671
1672 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1673 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1674 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1675 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1676 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1677 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1678 break;
1679 }
1680
1681 break;
1682
1683 case dt_pass:
1684 case dt_wall:
1685 case dt_walk:
1686 default:
1687 break;
1688 }
1689 }
1690
1691 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1692 {
1693 int32_t x=((pos&15)<<4)+xofs;
1694 int32_t y=(pos&0xF0)+yofs;
1695 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1696
1697
1698 switch(side)
1699 {
1700 case up:
1701 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1702 {
1703 overcombo(dest,x,y,
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1705 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1706 }
1707
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1709 {
1710 overcombo(dest,x+16,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1712
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1714 }
1715
1716 break;
1717
1718 case down:
1719 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1720 {
1721 overcombo(dest,x,y,
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1723 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1724 }
1725
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1727 {
1728 overcombo(dest,x+16,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1731 }
1732
1733 break;
1734
1735 case left:
1736 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1737 {
1738 overcombo(dest,x,y,
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1740 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1741 }
1742
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1744 {
1745 overcombo(dest,x,y+16,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1751 {
1752 overcombo(dest,x,y+32,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1755 }
1756
1757 break;
1758
1759 case right:
1760 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1761 {
1762 overcombo(dest,x,y,
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1764 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1765 }
1766
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1768 {
1769 overcombo(dest,x,y+16,
1770
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1773 }
1774
1775 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1776 {
1777 overcombo(dest,x,y+32,
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1780 }
1781
1782 break;
1783 }
1784 }
1785
1786 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1787 {
1788 word cmbcheck1, cmbcheck2;
1789 newcombo combocheck1, combocheck2;
1790 combocheck1 = combobuf[0];
1791 combocheck2 = combobuf[0];
1792 combocheck1.walk = 0;
1793 combocheck2.walk = 0;
1794
1795 int32_t layermap, layerscreen;
1796
1797 switch(dir)
1798 {
1799 case up:
1800 {
1801 if(i>15) //not top row of combos
1802 {
1803 return false;
1804 }
1805
1806 if(screen<16) //top row of screens
1807 {
1808 return false;
1809
1810 }
1811
1812 //check main screen
1813 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1814 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1815 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1816 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1817
1818 //check layer 1
1819 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1820
1821 if(layermap>-1 && layermap<map_count)
1822 {
1823 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1824 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1825 if (combobuf[cmbcheck1].type == cBRIDGE)
1826 {
1827 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1828 {
1829 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1830 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1831 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1832 }
1833 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1834 }
1835 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1836 }
1837
1838 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1839
1840 if(layermap>-1 && layermap<map_count)
1841 {
1842 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1843 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1844 if (combobuf[cmbcheck2].type == cBRIDGE)
1845 {
1846 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1847 {
1848 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1849 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1850 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1851 }
1852 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1853 }
1854 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1855 }
1856
1857 //check layer 2
1858 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1859
1860 if(layermap>-1 && layermap<map_count)
1861 {
1862 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1863
1864 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1865 if (combobuf[cmbcheck2].type == cBRIDGE)
1866 {
1867 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1868 {
1869 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1870 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1871 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1872 }
1873 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1874 }
1875 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1876 }
1877
1878 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1879
1880 if(layermap>-1 && layermap<map_count)
1881 {
1882 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1883 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1884 if (combobuf[cmbcheck2].type == cBRIDGE)
1885 {
1886 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1887 {
1888 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1889 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1890 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1891 }
1892 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1893 }
1894 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1895 }
1896
1897 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1898 {
1899 return true;
1900 }
1901
1902 break;
1903 }
1904 case down:
1905 {
1906 if(i<160) //not bottom row of combos
1907 {
1908 return false;
1909 }
1910
1911 if(screen>111) //bottom row of screens
1912 {
1913 return false;
1914 }
1915
1916 //check main screen
1917 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1918 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1919 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1920 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1921
1922
1923 //check layer 1
1924 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1925
1926 if(layermap>-1 && layermap<map_count)
1927 {
1928 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1929 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1930 if (combobuf[cmbcheck1].type == cBRIDGE)
1931 {
1932 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1933 {
1934 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1935 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1936 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1937 }
1938 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1939 }
1940 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1941 }
1942
1943 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1944
1945 if(layermap>-1 && layermap<map_count)
1946 {
1947 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1948 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1949 if (combobuf[cmbcheck2].type == cBRIDGE)
1950 {
1951 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1952 {
1953 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1954 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1955 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1956 }
1957 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1958 }
1959 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1960 }
1961
1962 //check layer 2
1963 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1964
1965 if(layermap>-1 && layermap<map_count)
1966 {
1967 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1968 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1969 if (combobuf[cmbcheck1].type == cBRIDGE)
1970 {
1971 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1972 {
1973 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1974 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1975 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1976 }
1977 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1978 }
1979 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1980 }
1981
1982 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1983
1984 if(layermap>-1 && layermap<map_count)
1985 {
1986 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1987 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1988 if (combobuf[cmbcheck2].type == cBRIDGE)
1989 {
1990 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1991 {
1992 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1993 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1994 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1995 }
1996 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1997 }
1998 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1999 }
2000
2001 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2002 {
2003 return true;
2004 }
2005
2006 break;
2007 }
2008 case left:
2009 {
2010 if((i&0xF)!=0) //not left column of combos
2011 {
2012 return false;
2013 }
2014
2015 if((screen&0xF)==0) //left column of screens
2016 {
2017 return false;
2018 }
2019
2020 //check main screen
2021 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2022 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2023 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2024 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2025
2026 //check layer 1
2027 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2028
2029 if(layermap>-1 && layermap<map_count)
2030 {
2031 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2032 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2033 if (combobuf[cmbcheck1].type == cBRIDGE)
2034 {
2035 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2036 {
2037 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2038 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2039 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2040 }
2041 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2042 }
2043 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2044 }
2045
2046 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2047
2048 if(layermap>-1 && layermap<map_count)
2049 {
2050 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2051 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2052 if (combobuf[cmbcheck2].type == cBRIDGE)
2053 {
2054 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2055 {
2056 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2057 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2058 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2059 }
2060 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2061 }
2062 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2063 }
2064
2065 //check layer 2
2066 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2067
2068 if(layermap>-1 && layermap<map_count)
2069 {
2070 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2071 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2072 if (combobuf[cmbcheck1].type == cBRIDGE)
2073 {
2074 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2075 {
2076 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2077 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2078 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2079 }
2080 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2081 }
2082 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2083 }
2084
2085 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2086
2087 if(layermap>-1 && layermap<map_count)
2088 {
2089 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2090 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2091 if (combobuf[cmbcheck2].type == cBRIDGE)
2092 {
2093 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2094 {
2095 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2096 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2097 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2098 }
2099 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2100 }
2101 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2102 }
2103
2104 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2105 {
2106 return true;
2107 }
2108
2109 break;
2110 }
2111 case right:
2112 {
2113 if((i&0xF)!=15) //not right column of combos
2114 {
2115 return false;
2116 }
2117
2118 if((screen&0xF)==15) //right column of screens
2119 {
2120 return false;
2121 }
2122
2123 //check main screen
2124 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2125 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2126 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2127 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2128
2129 //check layer 1
2130 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2131
2132 if(layermap>-1 && layermap<map_count)
2133 {
2134 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2135 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2136 if (combobuf[cmbcheck1].type == cBRIDGE)
2137 {
2138 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2139 {
2140 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2141 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2142 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2143 }
2144 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2145 }
2146 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2147 }
2148
2149 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2150
2151 if(layermap>-1 && layermap<map_count)
2152 {
2153 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2154 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2155 if (combobuf[cmbcheck2].type == cBRIDGE)
2156 {
2157 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2158 {
2159 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2160 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2161 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2162 }
2163 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2164 }
2165 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2166 }
2167
2168 //check layer 2
2169 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2170
2171 if(layermap>-1 && layermap<map_count)
2172 {
2173 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2174 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2175 if (combobuf[cmbcheck1].type == cBRIDGE)
2176 {
2177 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2178 {
2179 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2180 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2181 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2182 }
2183 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2184 }
2185 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2186 }
2187
2188 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2189
2190 if(layermap>-1 && layermap<map_count)
2191 {
2192 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2193
2194 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2195 if (combobuf[cmbcheck2].type == cBRIDGE)
2196 {
2197 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2198 {
2199 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2200 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2201 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2202 }
2203 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2204 }
2205 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2206 }
2207
2208 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2209 {
2210 return true;
2211 }
2212
2213 break;
2214 }
2215 }
2216
2217 return false;
2218 }
2219
2220 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2221 {
2222 int32_t checkcombo;
2223
2224 if(alignment_arrow_timer>31)
2225 {
2226 if(scr<0)
2227 {
2228 scr=cursor.screen;
2229 }
2230
2231 if((scr<128)) //do the misalignment arrows
2232 {
2233 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2234 {
2235 if(misaligned(cursor.map, scr, checkcombo, up))
2236 {
2237 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2238 }
2239 }
2240
2241 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2242 {
2243 if(misaligned(cursor.map, scr, checkcombo, down))
2244 {
2245 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2246 }
2247 }
2248
2249 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2250 {
2251 if(misaligned(cursor.map, scr, checkcombo, left))
2252 {
2253 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2254 }
2255 }
2256
2257 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2258 {
2259 if(misaligned(cursor.map, scr, checkcombo, right))
2260 {
2261 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2262 }
2263 }
2264
2265 int32_t tempalign;
2266
2267 //check top left corner
2268 checkcombo=0;
2269 tempalign=0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2271 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2272
2273 switch(tempalign)
2274 {
2275 case 0:
2276 break;
2277
2278 case 1: //up
2279 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2280 break;
2281
2282 case 2: //left
2283 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2284 break;
2285
2286 case 3: //up-left
2287 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2288 break;
2289 }
2290
2291 //check top right corner
2292 checkcombo=15;
2293 tempalign=0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2295 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2296
2297 switch(tempalign)
2298 {
2299 case 0:
2300 break;
2301
2302 case 1: //up
2303 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2304 break;
2305
2306 case 2: //right
2307 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2308 break;
2309
2310 case 3: //up-right
2311 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2312 break;
2313 }
2314
2315 //check bottom left corner
2316 checkcombo=160;
2317 tempalign=0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2319 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2320
2321 switch(tempalign)
2322 {
2323 case 0:
2324 break;
2325
2326 case 1: //down
2327 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2328 break;
2329
2330 case 2: //left
2331 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2332 break;
2333
2334 case 3: //down-left
2335 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2336 break;
2337 }
2338
2339 //check bottom right corner
2340
2341 checkcombo=175;
2342 tempalign=0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2344 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2345
2346 switch(tempalign)
2347 {
2348 case 0:
2349 break;
2350
2351 case 1: //down
2352 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2353 break;
2354
2355 case 2: //right
2356 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2357 break;
2358
2359 case 3: //down-right
2360 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2361 break;
2362 }
2363 }
2364 }
2365 }
2366
2367 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2368 {
2369 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2370 }
2371
2372 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2373 {
2374 if (map < 0 || screen < 0) return 0;
2375
2376 if(pos>175 || pos < 0)
2377 return 0;
2378
2379 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2380
2381 if (!m->is_valid()) return 0;
2382
2383 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2384
2385 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2386
2387 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2388
2389 if (!scr->is_valid()) return 0;
2390
2391 return scr->data[pos]; // entire combo code
2392 }
2393
2394 // Takes array index layer num., not actual layer num.
2395 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2396 {
2397 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2398
2399 if(map<0)
2400 map=cursor.map;
2401
2402 if(scr<0)
2403 scr=cursor.screen;
2404
2405 mapscr *screen1;
2406
2407 if(prv_mode)
2408 {
2409 screen1=get_prvscr();
2410 }
2411 else
2412 {
2413 screen1=AbsoluteScr(cursor.map,cursor.screen);
2414 }
2415
2416 int32_t layermap;
2417 layermap=screen1->layermap[lyr]-1;
2418
2419 if(layermap<0 || layermap >= map_count) return 0;
2420
2421 mapscr *layer;
2422
2423 if(prv_mode)
2424 layer = &prvlayers[lyr];
2425 else
2426 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2427
2428 int32_t pos = COMBOPOS(x,y);
2429
2430 if(pos>175 || pos < 0)
2431 return 0;
2432
2433 return layer->data[pos];
2434 }
2435
2436 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2437 {
2438 if(map<0)
2439 map=cursor.map;
2440
2441 if(scr<0)
2442 scr=cursor.screen;
2443
2444 mapscr *screen1;
2445
2446 if(prv_mode)
2447 {
2448 screen1=get_prvscr();
2449 }
2450 else
2451 {
2452 screen1=AbsoluteScr(cursor.map,cursor.screen);
2453 }
2454
2455 x = vbound(x, 0, 16*16);
2456 y = vbound(y, 0, 11*16);
2457 int32_t combo = COMBOPOS(x,y);
2458
2459 if(combo>175 || combo < 0)
2460 return 0;
2461
2462 return screen1->data[combo];
2463 }
2464
2465 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2466 {
2467 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2468 }
2469
2470 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2471 {
2472 if (map < 0 || screen < 0) return 0;
2473
2474 if(pos>175 || pos < 0)
2475 return 0;
2476
2477 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2478
2479 if (!m->is_valid()) return 0;
2480
2481 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2482
2483 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2484
2485 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2486
2487 if (!scr->is_valid()) return 0;
2488
2489 return scr->sflag[pos]; // entire combo code
2490 }
2491
2492 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2493 {
2494 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2495
2496 if(map<0)
2497 map=cursor.map;
2498
2499 if(scr<0)
2500 scr=cursor.screen;
2501
2502 mapscr *screen1;
2503
2504 if(prv_mode)
2505 {
2506 screen1=get_prvscr();
2507 }
2508 else
2509 {
2510 screen1=AbsoluteScr(cursor.map,cursor.screen);
2511 }
2512
2513 int32_t layermap;
2514 layermap=screen1->layermap[lyr]-1;
2515
2516 if(layermap<0 || layermap >= map_count) return 0;
2517
2518 mapscr *layer;
2519
2520 if(prv_mode)
2521 layer = &prvlayers[lyr];
2522 else
2523 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2524
2525 int32_t combo = COMBOPOS(x,y);
2526
2527 if(combo>175 || combo < 0)
2528 return 0;
2529
2530 return layer->sflag[combo];
2531 }
2532
2533 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2534 {
2535 if(map<0)
2536 map=cursor.map;
2537
2538 if(scr<0)
2539 scr=cursor.screen;
2540
2541 mapscr *screen1;
2542
2543 if(prv_mode)
2544 {
2545 screen1=get_prvscr();
2546 }
2547 else
2548 {
2549 screen1=AbsoluteScr(cursor.map,cursor.screen);
2550 }
2551
2552 x = vbound(x, 0, 16*16);
2553 y = vbound(y, 0, 11*16);
2554 int32_t combo = COMBOPOS(x,y);
2555
2556 if(combo>175 || combo < 0)
2557 return 0;
2558
2559 return screen1->sflag[combo];
2560 }
2561
2562 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2563 {
2564 mapscr *layers[7];
2565 mapscr *basescr;
2566 if(prv_mode)
2567 {
2568 layers[0] = &prvscr;
2569 basescr = layers[0];
2570 for(auto q = 1; q < 7; ++q)
2571 {
2572 if(prvlayers[q-1].valid)
2573 layers[q] = &(prvlayers[q-1]);
2574 else layers[q] = NULL;
2575 }
2576 }
2577 else
2578 {
2579 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2580 basescr = layers[0];
2581 for(auto q = 1; q < 7; ++q)
2582 {
2583 int32_t lmap = basescr->layermap[q-1]-1;
2584 int32_t lscr = basescr->layerscreen[q-1];
2585 if(lmap < 0)
2586 layers[q] = NULL;
2587 else layers[q] = AbsoluteScr(lmap, lscr);
2588 }
2589 }
2590 for(auto q = 0; q < 7; ++q)
2591 {
2592 if(!layers[q]) continue;
2593 for(auto pos = 0; pos < 176; ++pos)
2594 {
2595 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2596 if(cmb.type == cTORCH)
2597 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2598 }
2599 }
2600 word maxffc = basescr->numFFC();
2601 for(auto q = 0; q < maxffc; ++q)
2602 {
2603 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2604 if(cmb.type == cTORCH)
2605 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2606 }
2607 }
2608
2609 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2610 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2611 {
2612 newcombo const& cmb = combobuf[cid];
2613 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2614 if(dither)
2615 {
2616 if (LayerDitherSz == 0)
2617 return;
2618 BITMAP* buf = create_bitmap_ex(8,16,16);
2619 clear_bitmap(buf);
2620 overcombo(buf,0,0,cid,cset);
2621 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2622 if(over)
2623 {
2624 if(transp)
2625 {
2626 color_map = &trans_table2;
2627 draw_trans_sprite(dest, buf, x, y);
2628 color_map = &trans_table;
2629 }
2630 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2631 }
2632 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2633 destroy_bitmap(buf);
2634 }
2635 else if(over)
2636 {
2637 if(transp)
2638 overcombotranslucent(dest,x,y,cid,cset,0);
2639 else overcombo(dest,x,y,cid,cset);
2640 }
2641 else put_combo(dest,x,y,cid,cset,flags,sflag);
2642 }
2643 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2644 {
2645 if(!md) return;
2646 for (int32_t i = 0; i < 176; i++)
2647 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2648 }
2649 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2650 {
2651 if(!md) return;
2652 for (int32_t i = 0; i < 176; i++)
2653 {
2654 int data = md->data[i];
2655 if(combo_class_buf[combobuf[data].type].overhead)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2657 }
2658 }
2659 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2660 {
2661 if(!LayerMaskInt[lyr])
2662 return nullptr;
2663 if(lyr == 0)
2664 return basescr;
2665 int layermap = basescr->layermap[lyr-1]-1;
2666
2667 if(layermap>-1 && layermap<map_count)
2668 {
2669 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2670 return &TheMaps[layerscreen];
2671 }
2672 return nullptr;
2673 }
2674 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2675 {
2676 int num_ffcs = basescr->numFFC();
2677 for(int32_t i=num_ffcs-1; i>=0; i--)
2678 {
2679 auto const& ff = basescr->ffcs[i];
2680 if(ff.data)
2681 {
2682 if(!(ff.flags&ffc_changer))
2683 {
2684 int32_t tx=(ff.x.getInt())+x;
2685 int32_t ty=(ff.y.getInt())+y;
2686
2687 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2688 {
2689 if(ff.flags&ffc_trans)
2690 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2691 else
2692 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2693 }
2694 }
2695 }
2696 }
2697 }
2698 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2699 {
2700 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2701 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2702
2703 if(map<0)
2704 map=cursor.map;
2705
2706 if(screen<0)
2707 screen=cursor.screen;
2708
2709 mapscr *basescr;
2710 mapscr* layers[7] = {nullptr};
2711
2712 if(prv_mode)
2713 {
2714 hl_layer = -1;
2715 basescr=get_prvscr();
2716 }
2717 else
2718 {
2719 basescr=AbsoluteScr(map,screen);
2720 }
2721 layers[0] = _zmap_get_lyr_checked(0,basescr);
2722 for(int lyr = 1; lyr < 7; ++lyr)
2723 {
2724 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2725 : _zmap_get_lyr_checked(lyr,basescr);
2726 }
2727
2728 if(!(basescr->valid&mVALID))
2729 {
2730 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2731 rectfill(dest,x,y,x+255,y+175,vc(1));
2732
2733 if(ShowMisalignments)
2734 {
2735 check_alignments(dest,x,y,screen);
2736 }
2737
2738 return;
2739 }
2740
2741 if(LayerMaskInt[0]==0)
2742 {
2743 byte bgfill = 0;
2744 if (LayerDitherBG > -1)
2745 bgfill = vc(LayerDitherBG);
2746 rectfill(dest,x,y,x+255,y+175,bgfill);
2747 }
2748
2749 if(get_qr(qr_CLASSIC_DRAWING_ORDER))
2750 {
2751 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2752 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2753 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2754 }
2755
2756 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2757 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2758 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2759
2760 if(!get_qr(qr_CLASSIC_DRAWING_ORDER))
2761 {
2762 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2763 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2764 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2765 }
2766
2767 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !get_qr(qr_CLASSIC_DRAWING_ORDER) || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2768 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2769
2770
2771 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2772 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2773
2774 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2775 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2776 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2777
2778 int32_t doortype[4];
2779
2780 for(int32_t i=0; i<4; i++)
2781 {
2782 switch(basescr->door[i])
2783 {
2784 case dOPEN:
2785 doortype[i]=dt_pass;
2786 break;
2787
2788 case dLOCKED:
2789 doortype[i]=dt_lock;
2790 break;
2791
2792 case d1WAYSHUTTER:
2793 case dSHUTTER:
2794 doortype[i]=dt_shut;
2795 break;
2796
2797 case dBOSS:
2798 doortype[i]=dt_boss;
2799 break;
2800
2801 case dBOMB:
2802 doortype[i]=dt_bomb;
2803 break;
2804 }
2805 }
2806
2807 switch(basescr->door[up])
2808 {
2809 case dBOMB:
2810 over_door(dest,39,up,x,y,false, screen);
2811 [[fallthrough]];
2812 case dOPEN:
2813 case dLOCKED:
2814 case d1WAYSHUTTER:
2815 case dSHUTTER:
2816 case dBOSS:
2817 put_door(dest,7,up,doortype[up],x,y,false,screen);
2818 break;
2819
2820 case dWALK:
2821 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2822 {
2823 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2824 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2825 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2826 }
2827 else
2828
2829 {
2830 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2831 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2832 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2833 }
2834
2835 break;
2836 }
2837
2838 switch(basescr->door[down])
2839 {
2840 case dBOMB:
2841 over_door(dest,135,down,x,y,false,screen);
2842 [[fallthrough]];
2843 case dOPEN:
2844 case dLOCKED:
2845 case d1WAYSHUTTER:
2846 case dSHUTTER:
2847 case dBOSS:
2848 put_door(dest,151,down,doortype[down],x,y,false,screen);
2849 break;
2850
2851 case dWALK:
2852 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2853 {
2854 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2855 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2856 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2857 }
2858 else
2859 {
2860 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2861 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2862 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2863 }
2864
2865 break;
2866 }
2867
2868 switch(basescr->door[left])
2869 {
2870 case dBOMB:
2871 over_door(dest,66,left,x,y,false,screen);
2872 [[fallthrough]];
2873 case dOPEN:
2874 case dLOCKED:
2875 case d1WAYSHUTTER:
2876 case dSHUTTER:
2877 case dBOSS:
2878 put_door(dest,64,left,doortype[left],x,y,false,screen);
2879 break;
2880
2881 case dWALK:
2882 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2883 {
2884 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2885 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2886 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2887 }
2888 else
2889 {
2890 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2891 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2892 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2893 }
2894
2895 break;
2896 }
2897
2898 switch(basescr->door[right])
2899 {
2900
2901 case dBOMB:
2902 over_door(dest,77,right,x,y,false,screen);
2903 [[fallthrough]];
2904 case dOPEN:
2905 case dLOCKED:
2906 case d1WAYSHUTTER:
2907 case dSHUTTER:
2908 case dBOSS:
2909 put_door(dest,78,right,doortype[right],x,y,false,screen);
2910 break;
2911
2912 case dWALK:
2913 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2914 {
2915 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2916 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2917 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2918 }
2919 else
2920 {
2921 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2922 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2923 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2924 }
2925
2926 break;
2927 }
2928
2929 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2930 {
2931 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2932 }
2933
2934 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2935 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2936 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2937
2938 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2939 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2940
2941 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2942
2943 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2944 {
2945 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2946 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2947 }
2948 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2949 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2950
2951 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2952
2953 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2954 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2955 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2956
2957 int num_ffcs = basescr->numFFC();
2958 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2959 if(basescr->ffcs[i].data)
2960 if(basescr->ffcs[i].flags&ffc_changer)
2961 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2962
2963 if(flags&cWALK)
2964 {
2965 if(layers[0])
2966 for(int32_t i=0; i<176; i++)
2967 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2968
2969 for(int32_t k=0; k<2; k++)
2970 {
2971 if(layers[k+1])
2972 for(int32_t i=0; i<176; i++)
2973 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2974 }
2975 for(int32_t i=num_ffcs-1; i>=0; i--)
2976 {
2977 if(auto data = basescr->ffcs[i].data)
2978 {
2979 if(!(basescr->ffcs[i].flags&ffc_changer))
2980 {
2981 newcombo const& cmb = combobuf[data];
2982 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2983 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2984
2985 if(basescr->ffcs[i].flags&ffc_solid)
2986 {
2987 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2988 }
2989
2990 if(cmb.type == cSLOPE)
2991 {
2992 slope_info s(cmb, tx, ty);
2993 s.draw(dest, 0, 0, COLOR_SLOPE);
2994 }
2995 }
2996 }
2997 }
2998 }
2999
3000 if(flags&cFLAGS)
3001 {
3002 if(LayerMaskInt[CurrentLayer]!=0)
3003 {
3004 for(int32_t i=0; i<176; i++)
3005 {
3006 if(CurrentLayer==0)
3007 {
3008 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3009 }
3010 else
3011 {
3012 if(prv_mode)
3013 {
3014 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3015 }
3016 else if(basescr->layermap[CurrentLayer-1] > 0)
3017 {
3018 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3019
3020 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3021 {
3022 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3023 TheMaps[_lscr].data[i],
3024 TheMaps[_lscr].cset[i], flags,
3025 TheMaps[_lscr].sflag[i]);
3026 }
3027 }
3028 }
3029 }
3030 }
3031 }
3032
3033 int32_t dark = basescr->flags&cDARK;
3034
3035 if(dark && !(flags&cNODARK)
3036 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3037 {
3038 for(int32_t j=0; j<80; j++)
3039 {
3040 for(int32_t i=0; i<(80)-j; i++)
3041 {
3042 if(((i^j)&1)==0)
3043 {
3044 putpixel(dest,x+i,y+j,vc(blackout_color));
3045 }
3046 }
3047 }
3048 }
3049
3050 if(ShowMisalignments)
3051 {
3052 check_alignments(dest,x,y,screen);
3053 }
3054 }
3055
3056 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3057 {
3058 if(map<0)
3059 map=cursor.map;
3060
3061 if(scr<0)
3062 scr=cursor.screen;
3063
3064 mapscr* layer=AbsoluteScr(map,scr);
3065 int32_t layermap=0, layerscreen=0;
3066
3067 if(!(layer->valid&mVALID))
3068 {
3069 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3070 rectfill(dest,x,y,x+255,y+15,vc(1));
3071 return;
3072 }
3073
3074 int32_t dark = layer->flags&4;
3075
3076 if(LayerMaskInt[0]==0)
3077 {
3078 rectfill(dest,x,y,x+255,y+15,0);
3079 }
3080
3081 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3082 int order[2] = {2,1};
3083 if (olddraw) zc_swap(order[0],order[1]);
3084 for(int k : order)
3085 {
3086 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3087 {
3088 layermap=layer->layermap[k]-1;
3089
3090 if(layermap>-1 && layermap<map_count)
3091 {
3092 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3093
3094 for(int32_t i=c; i<(c&0xF0)+16; i++)
3095 {
3096 auto data = TheMaps[layerscreen].data[i];
3097 auto cs = TheMaps[layerscreen].cset[i];
3098 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3099 }
3100 }
3101 }
3102 }
3103
3104 if(LayerMaskInt[0]!=0)
3105 {
3106 for(int32_t i=c; i<(c&0xF0)+16; i++)
3107 {
3108 word cmbdat = (i < 176 ? layer->data[i] : 0);
3109 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3110 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3111 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3112 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3113 }
3114 }
3115
3116 for(int32_t k=0; k<2; k++)
3117 {
3118 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3119 {
3120 layermap=layer->layermap[k]-1;
3121
3122 if(layermap>-1 && layermap<map_count)
3123 {
3124 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3125
3126 for(int32_t i=c; i<(c&0xF0)+16; i++)
3127 {
3128 auto data = TheMaps[layerscreen].data[i];
3129 auto cs = TheMaps[layerscreen].cset[i];
3130 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3131 }
3132 }
3133 }
3134 }
3135
3136 int32_t doortype[4];
3137
3138 for(int32_t i=0; i<4; i++)
3139 {
3140 switch(layer->door[i])
3141 {
3142 case dOPEN:
3143 doortype[i]=dt_pass;
3144 break;
3145
3146 case dLOCKED:
3147 doortype[i]=dt_lock;
3148 break;
3149
3150 case d1WAYSHUTTER:
3151 case dSHUTTER:
3152 doortype[i]=dt_shut;
3153 break;
3154
3155 case dBOSS:
3156 doortype[i]=dt_boss;
3157 break;
3158
3159 case dBOMB:
3160 doortype[i]=dt_bomb;
3161 break;
3162 }
3163 }
3164
3165 if(c<16)
3166 {
3167 switch(layer->door[up])
3168 {
3169 case dBOMB:
3170 case dOPEN:
3171 case dLOCKED:
3172 case d1WAYSHUTTER:
3173 case dSHUTTER:
3174 case dBOSS:
3175 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3176 break;
3177 }
3178 }
3179 else if(c>159)
3180 {
3181 switch(layer->door[down])
3182 {
3183 case dBOMB:
3184 case dOPEN:
3185 case dLOCKED:
3186 case d1WAYSHUTTER:
3187 case dSHUTTER:
3188 case dBOSS:
3189 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3190 break;
3191 }
3192 }
3193
3194 for(int32_t k=2; k<4; k++)
3195 {
3196 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3197 {
3198 layermap=layer->layermap[k]-1;
3199
3200 if(layermap>-1 && layermap<map_count)
3201 {
3202 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3203
3204 for(int32_t i=c; i<(c&0xF0)+16; i++)
3205 {
3206 if(layer->layeropacity[k]<255)
3207 {
3208 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3209 }
3210 else
3211 {
3212 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3213 }
3214 }
3215 }
3216 }
3217 }
3218
3219 //Overhead L0
3220 if(LayerMaskInt[0]!=0)
3221 {
3222 for(int32_t i=c; i<(c&0xF0)+16; i++)
3223 {
3224 int32_t ct1=layer->data[i];
3225 int32_t ct3=combobuf[ct1].type;
3226
3227 if(combo_class_buf[ct3].overhead)
3228 {
3229 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3230 }
3231 }
3232 }
3233
3234 //Overhead L1/2
3235 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3236 {
3237 for(int32_t k = 0; k < 2; ++k)
3238 {
3239 if(LayerMaskInt[k+1]!=0)
3240 {
3241 layermap=layer->layermap[k]-1;
3242
3243 if(layermap>-1 && layermap<map_count)
3244 {
3245 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3246 for(int32_t i=c; i<(c&0xF0)+16; i++)
3247 {
3248 auto data = TheMaps[layerscreen].data[i];
3249 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3250 auto cs = TheMaps[layerscreen].cset[i];
3251 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3252 }
3253 }
3254 }
3255 }
3256 }
3257
3258 for(int32_t k=4; k<6; k++)
3259 {
3260 if(LayerMaskInt[k+1]!=0)
3261 {
3262 layermap=layer->layermap[k]-1;
3263
3264 if(layermap>-1 && layermap<map_count)
3265 {
3266 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3267
3268 for(int32_t i=c; i<(c&0xF0)+16; i++)
3269 {
3270 auto data = TheMaps[layerscreen].data[i];
3271 auto cs = TheMaps[layerscreen].cset[i];
3272 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3273 }
3274 }
3275 }
3276 }
3277
3278 if(flags&cWALK)
3279 {
3280 if(LayerMaskInt[0]!=0)
3281 {
3282 for(int32_t i=c; i<(c&0xF0)+16; i++)
3283 {
3284 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3285 }
3286 }
3287
3288 for(int32_t k=0; k<2; k++)
3289 {
3290 if(LayerMaskInt[k+1]!=0)
3291 {
3292 for(int32_t i=c; i<(c&0xF0)+16; i++)
3293 {
3294 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3295 }
3296 }
3297 }
3298 }
3299
3300 if(flags&cFLAGS)
3301 {
3302 if(LayerMaskInt[CurrentLayer]!=0)
3303 {
3304 for(int32_t i=c; i<(c&0xF0)+16; i++)
3305 {
3306 if(CurrentLayer==0)
3307 {
3308 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3309 }
3310 else
3311 {
3312 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3313
3314 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3315 {
3316 if(i < 176)
3317 {
3318 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3319 TheMaps[_lscr].data[i],
3320 TheMaps[_lscr].cset[i], flags|dark,
3321 TheMaps[_lscr].sflag[i]);
3322 }
3323 else
3324 {
3325 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3326 }
3327 }
3328 }
3329 }
3330 }
3331
3332 /*
3333 if (LayerMaskInt[0]!=0) {
3334 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3335 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3336 }
3337 }
3338 */
3339 }
3340
3341 if(ShowMisalignments)
3342 {
3343 if(c<16)
3344 {
3345 check_alignments(dest,x,y,scr);
3346 }
3347 else if(c>159)
3348 {
3349 check_alignments(dest,x,y-160,scr);
3350 }
3351 }
3352 }
3353
3354 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3355 {
3356 if(map<0)
3357 map=cursor.map;
3358
3359 if(scr<0)
3360 scr=cursor.screen;
3361
3362 mapscr* layer=AbsoluteScr(map,scr);
3363 int32_t layermap=0, layerscreen=0;
3364
3365 if(!(layer->valid&mVALID))
3366 {
3367 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3368 rectfill(dest,x,y,x+15,y+175,vc(1));
3369 return;
3370 }
3371
3372 int32_t dark = layer->flags&4;
3373
3374 if(LayerMaskInt[0]==0)
3375 {
3376 rectfill(dest,x,y,x+15,y+175,0);
3377 }
3378
3379 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3380 int order[2] = {2,1};
3381 if (olddraw) zc_swap(order[0],order[1]);
3382 for(int k : order)
3383 {
3384 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3385 {
3386 layermap=layer->layermap[k]-1;
3387
3388 if(layermap>-1 && layermap<map_count)
3389 {
3390 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3391
3392 for(int32_t i=c; i<176; i+=16)
3393 {
3394 auto data = TheMaps[layerscreen].data[i];
3395 auto cs = TheMaps[layerscreen].cset[i];
3396 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3397 }
3398 }
3399 }
3400 }
3401
3402 if(LayerMaskInt[0]!=0)
3403 {
3404 for(int32_t i=c; i<176; i+=16)
3405 {
3406 word cmbdat = layer->data[i];
3407 byte cmbcset = layer->cset[i];
3408 int32_t cmbflag = layer->sflag[i];
3409 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3410 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3411 }
3412 }
3413
3414 for(int32_t k=0; k<2; k++)
3415 {
3416 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3417 {
3418 layermap=layer->layermap[k]-1;
3419
3420 if(layermap>-1 && layermap<map_count)
3421 {
3422 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3423
3424 for(int32_t i=c; i<176; i+=16)
3425 {
3426 auto data = TheMaps[layerscreen].data[i];
3427 auto cs = TheMaps[layerscreen].cset[i];
3428 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3429 }
3430 }
3431 }
3432 }
3433
3434 int32_t doortype[4];
3435
3436 for(int32_t i=0; i<4; i++)
3437 {
3438 switch(layer->door[i])
3439 {
3440 case dOPEN:
3441 doortype[i]=dt_pass;
3442 break;
3443
3444 case dLOCKED:
3445 doortype[i]=dt_lock;
3446 break;
3447
3448 case d1WAYSHUTTER:
3449 case dSHUTTER:
3450 doortype[i]=dt_shut;
3451 break;
3452
3453 case dBOSS:
3454 doortype[i]=dt_boss;
3455 break;
3456
3457 case dBOMB:
3458 doortype[i]=dt_bomb;
3459 break;
3460 }
3461 }
3462
3463 if((c&0x0F)==0)
3464 {
3465 switch(layer->door[left])
3466 {
3467
3468 case dBOMB:
3469 case dOPEN:
3470 case dLOCKED:
3471 case d1WAYSHUTTER:
3472 case dSHUTTER:
3473 case dBOSS:
3474 // put_door(dest,64,left,doortype[left],x+256,y,true);
3475 put_door(dest,64,left,doortype[left],x,y,true,scr);
3476 break;
3477 }
3478 }
3479 else if((c&0x0F)==15)
3480 {
3481 switch(layer->door[right])
3482 {
3483 case dBOMB:
3484 case dOPEN:
3485 case dLOCKED:
3486 case d1WAYSHUTTER:
3487 case dSHUTTER:
3488 case dBOSS:
3489 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3490 break;
3491 }
3492 }
3493
3494 for(int32_t k=2; k<4; k++)
3495 {
3496 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3497 {
3498 layermap=layer->layermap[k]-1;
3499
3500 if(layermap>-1 && layermap<map_count)
3501 {
3502 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3503
3504 for(int32_t i=c; i<176; i+=16)
3505 {
3506 auto data = TheMaps[layerscreen].data[i];
3507 auto cs = TheMaps[layerscreen].cset[i];
3508 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3509 }
3510 }
3511 }
3512 }
3513
3514 //Overhead L0
3515 if(LayerMaskInt[0]!=0)
3516 {
3517 for(int32_t i=c; i<176; i+=16)
3518 {
3519 auto data = TheMaps[layerscreen].data[i];
3520 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3521 auto cs = TheMaps[layerscreen].cset[i];
3522 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3523 }
3524 }
3525 //Overhead L1/2
3526 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3527 {
3528 for(int32_t k = 0; k < 2; ++k)
3529 {
3530 if(LayerMaskInt[k+1]!=0)
3531 {
3532 layermap=layer->layermap[k]-1;
3533
3534 if(layermap>-1 && layermap<map_count)
3535 {
3536 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3537 for(int32_t i=c; i<176; i+=16)
3538 {
3539 auto data = TheMaps[layerscreen].data[i];
3540 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3541 auto cs = TheMaps[layerscreen].cset[i];
3542 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3543 }
3544 }
3545 }
3546 }
3547 }
3548
3549
3550 for(int32_t k=4; k<6; k++)
3551 {
3552 if(LayerMaskInt[k+1]!=0)
3553 {
3554 layermap=layer->layermap[k]-1;
3555
3556 if(layermap>-1 && layermap<map_count)
3557 {
3558 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3559
3560 for(int32_t i=c; i<176; i+=16)
3561 {
3562 auto data = TheMaps[layerscreen].data[i];
3563 auto cs = TheMaps[layerscreen].cset[i];
3564 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3565 }
3566 }
3567 }
3568 }
3569
3570 if(flags&cWALK)
3571 {
3572 if(LayerMaskInt[0]!=0)
3573 {
3574 for(int32_t i=c&0xF; i<176; i+=16)
3575 {
3576 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3577 }
3578 }
3579
3580 for(int32_t k=0; k<2; k++)
3581 {
3582 if(LayerMaskInt[k+1]!=0)
3583 {
3584 for(int32_t i=c&0xF; i<176; i+=16)
3585 {
3586 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3587 }
3588 }
3589 }
3590 }
3591
3592 if(flags&cFLAGS)
3593 {
3594 if(LayerMaskInt[CurrentLayer]!=0)
3595 {
3596 for(int32_t i=c; i<176; i+=16)
3597 {
3598 if(CurrentLayer==0)
3599 {
3600 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3601 }
3602 else
3603 {
3604 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3605
3606 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3607 {
3608 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3609 TheMaps[_lscr].data[i],
3610 TheMaps[_lscr].cset[i], flags|dark,
3611 TheMaps[_lscr].sflag[i]);
3612 }
3613 }
3614 }
3615 }
3616 }
3617
3618 if(ShowMisalignments)
3619 {
3620 if((c&0x0F)==0)
3621 {
3622 check_alignments(dest,x,y,scr);
3623 }
3624 else if((c&0x0F)==15)
3625 {
3626 check_alignments(dest,x-240,y,scr);
3627 }
3628 }
3629 }
3630
3631 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3632 {
3633 if(map<0)
3634 map=cursor.map;
3635
3636 if(scr<0)
3637 scr=cursor.screen;
3638
3639 mapscr* layer=AbsoluteScr(map,scr);
3640 int32_t layermap=0, layerscreen=0;
3641
3642 if(!(layer->valid&mVALID))
3643 {
3644 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3645 rectfill(dest,x,y,x+15,y+15,vc(1));
3646 return;
3647 }
3648
3649 int32_t dark = layer->flags&4;
3650
3651 if(LayerMaskInt[0]!=0)
3652 {
3653 rectfill(dest,x,y,x+15,y+15,0);
3654 }
3655
3656 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3657 int order[2] = {2,1};
3658 if (olddraw) zc_swap(order[0],order[1]);
3659 for(int k : order)
3660 {
3661 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3662 {
3663 layermap=layer->layermap[k]-1;
3664
3665 if(layermap>-1 && layermap<map_count)
3666 {
3667 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3668
3669 auto data = TheMaps[layerscreen].data[c];
3670 auto cs = TheMaps[layerscreen].cset[c];
3671 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3672 }
3673 }
3674 }
3675
3676 if(LayerMaskInt[0]!=0)
3677 {
3678 word cmbdat = layer->data[c];
3679 byte cmbcset = layer->cset[c];
3680 int32_t cmbflag = layer->sflag[c];
3681 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3682 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3683 }
3684
3685
3686 for(int32_t k=0; k<2; k++)
3687 {
3688 if(LayerMaskInt[k+1]!=0)
3689 {
3690 layermap=layer->layermap[k]-1;
3691
3692 if(layermap>-1 && layermap<map_count)
3693 {
3694 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3695
3696 auto data = TheMaps[layerscreen].data[c];
3697 auto cs = TheMaps[layerscreen].cset[c];
3698 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3699 }
3700 }
3701 }
3702
3703 for(int32_t k=2; k<4; k++)
3704 {
3705 if(LayerMaskInt[k+1]!=0)
3706 {
3707 layermap=layer->layermap[k]-1;
3708
3709 if(layermap>-1 && layermap<map_count)
3710 {
3711 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3712 auto data = TheMaps[layerscreen].data[c];
3713 auto cs = TheMaps[layerscreen].cset[c];
3714 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3715 }
3716 }
3717 }
3718
3719 //Overhead L0
3720 if(LayerMaskInt[0]!=0)
3721 {
3722 auto data = TheMaps[layerscreen].data[c];
3723 if(combo_class_buf[combobuf[data].type].overhead)
3724 {
3725 auto cs = TheMaps[layerscreen].cset[c];
3726 drawcombo(dest,x,y,data,cs,0,0);
3727 }
3728 }
3729 //Overhead L1/2
3730 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3731 {
3732 for(int32_t k = 0; k < 2; ++k)
3733 {
3734 if(LayerMaskInt[k+1]!=0)
3735 {
3736 layermap=layer->layermap[k]-1;
3737
3738 if(layermap>-1 && layermap<map_count)
3739 {
3740 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3741 auto data = TheMaps[layerscreen].data[c];
3742 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3743 auto cs = TheMaps[layerscreen].cset[c];
3744 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3745 }
3746 }
3747 }
3748 }
3749
3750
3751 for(int32_t k=4; k<6; k++)
3752 {
3753 if(LayerMaskInt[k+1]!=0)
3754 {
3755 layermap=layer->layermap[k]-1;
3756
3757 if(layermap>-1 && layermap<map_count)
3758 {
3759 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3760 auto data = TheMaps[layerscreen].data[c];
3761 auto cs = TheMaps[layerscreen].cset[c];
3762 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3763 }
3764 }
3765 }
3766
3767 if(flags&cWALK)
3768 {
3769 if(LayerMaskInt[0]!=0)
3770 {
3771 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3772 }
3773
3774 for(int32_t k=0; k<2; k++)
3775 {
3776 if(LayerMaskInt[k+1]!=0)
3777 {
3778 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3779 }
3780 }
3781 }
3782
3783 if(flags&cFLAGS)
3784 {
3785 if(LayerMaskInt[CurrentLayer]!=0)
3786 {
3787 int32_t i = c;
3788 //for(int32_t i=c; i==c; i++)
3789 {
3790 if(CurrentLayer==0)
3791 {
3792 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3793 }
3794 else
3795 {
3796 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3797
3798 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3799 {
3800 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3801 TheMaps[_lscr].data[i],
3802 TheMaps[_lscr].cset[i], flags|dark,
3803 TheMaps[_lscr].sflag[i]);
3804 }
3805 }
3806 }
3807 }
3808 }
3809
3810 if(ShowMisalignments)
3811 {
3812 switch(c)
3813 {
3814 case 0:
3815 check_alignments(dest,x,y,scr);
3816 break;
3817
3818 case 15:
3819 check_alignments(dest,x-240,y,scr);
3820 break;
3821
3822 case 160:
3823 check_alignments(dest,x,y-160,scr);
3824 break;
3825
3826 case 175:
3827 check_alignments(dest,x-240,y-160,scr);
3828 break;
3829 }
3830 }
3831 }
3832
3833 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3834 {
3835 if (InvalidBG == 2)
3836 {
3837 draw_checkerboard(dest, x, y, 16);
3838 }
3839 else if(InvalidBG == 1)
3840 {
3841 for(int32_t dy=0; dy<16; dy++)
3842 {
3843 for(int32_t dx=0; dx<16; dx++)
3844 {
3845 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3846 }
3847 }
3848 }
3849 else
3850 {
3851 rectfill(dest, x, y, x+15, y+15, vc(0));
3852 rect(dest, x, y, x+15, y+15, vc(15));
3853 line(dest, x, y, x+15, y+15, vc(15));
3854 line(dest, x, y+15, x+15, y, vc(15));
3855 }
3856 }
3857
3858 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3859 {
3860 if (InvalidBG == 2)
3861 {
3862 for(int32_t q = 0; q < 11; ++q)
3863 draw_checkerboard(dest, x, y + q * 16, 16);
3864 }
3865 else if(InvalidBG == 1)
3866 {
3867 for(int32_t dy=0; dy<176; dy++)
3868 {
3869 for(int32_t dx=0; dx<16; dx++)
3870 {
3871 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3872 }
3873 }
3874 }
3875 else
3876 {
3877 rectfill(dest, x, y, x+15, y+175, vc(0));
3878 rect(dest, x, y, x+15, y+175, vc(15));
3879 line(dest, x, y, x+15, y+175, vc(15));
3880 line(dest, x, y+175, x+15, y, vc(15));
3881 }
3882 }
3883
3884 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3885 {
3886 if (InvalidBG == 2)
3887 {
3888 for (int32_t q = 0; q < 16; ++q)
3889 draw_checkerboard(dest, x + q * 16, y, 16);
3890 }
3891 else if(InvalidBG == 1)
3892 {
3893 for(int32_t dy=0; dy<16; dy++)
3894 {
3895 for(int32_t dx=0; dx<256; dx++)
3896 {
3897 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3898 }
3899 }
3900 }
3901 else
3902 {
3903 rectfill(dest, x, y, x+255, y+15, vc(0));
3904 rect(dest, x, y, x+255, y+15, vc(15));
3905 line(dest, x, y, x+255, y+15, vc(15));
3906 line(dest, x, y+15, x+255, y, vc(15));
3907 }
3908 }
3909
3910 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3911 {
3912 for(int32_t i=0; i<176; i++)
3913 {
3914 word cmbdat = screens[TEMPLATE].data[i];
3915 byte cmbcset = screens[TEMPLATE].cset[i];
3916 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3917 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3918 }
3919 }
3920
3921 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3922 {
3923 for(int32_t i=0; i<176; i++)
3924 {
3925 word cmbdat = screens[TEMPLATE2].data[i];
3926 byte cmbcset = screens[TEMPLATE2].cset[i];
3927 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3928 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3929 }
3930 }
3931
3932 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3933 {
3934 word cmbdat = screens[TEMPLATE].data[pos];
3935 byte cmbcset = screens[TEMPLATE].cset[pos];
3936 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3937 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3938 }
3939
3940 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3941 {
3942 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3943 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3944 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3945 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3946 }
3947
3948 void zmap::scroll(int32_t dir, bool warp)
3949 {
3950 if(cursor.map<map_count)
3951 {
3952 switch(dir)
3953 {
3954 case up:
3955 if(warp && Map.CurrScr()->flags2&wfUP)
3956 {
3957 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3958 }
3959 else if(cursor.screen>15)
3960 {
3961 setCurrScr(cursor.screen - 16);
3962 }
3963
3964 break;
3965
3966 case down:
3967 if(warp && Map.CurrScr()->flags2&wfDOWN)
3968 {
3969 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3970 }
3971 else if(cursor.screen<MAPSCRS-16)
3972 {
3973 setCurrScr(cursor.screen + 16);
3974 }
3975
3976 break;
3977
3978 case left:
3979 if(warp && Map.CurrScr()->flags2&wfLEFT)
3980 {
3981 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3982 }
3983 else if(cursor.screen&15)
3984 {
3985 setCurrScr(cursor.screen - 1);
3986 }
3987
3988 break;
3989
3990 case right:
3991 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3992 {
3993 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3994 }
3995 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3996 {
3997 setCurrScr(cursor.screen + 1);
3998 }
3999
4000 break;
4001 }
4002 }
4003 }
4004
4005 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4006 {
4007 switch(side)
4008 {
4009 case up:
4010 switch(door)
4011 {
4012 case dWALL:
4013 case dBOMB:
4014 case dWALK:
4015 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4016 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4017 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4018 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4019 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4020 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4021 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4022 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4023 break;
4024
4025 default:
4026 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4027 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4028 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4029 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4030 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4031 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4032 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4033 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4034 break;
4035 }
4036
4037 break;
4038
4039 case down:
4040 switch(door)
4041 {
4042 case dWALL:
4043 case dBOMB:
4044 case dWALK:
4045 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4046 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4047 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4048 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4049 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4050 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4051 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4052 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4053 break;
4054
4055 default:
4056 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4057 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4058 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4059 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4060 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4061 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4062 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4063 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4064 break;
4065 }
4066
4067 break;
4068
4069 case left:
4070 switch(door)
4071 {
4072 case dWALL:
4073 case dBOMB:
4074 case dWALK:
4075 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4076 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4077 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4078 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4079 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4080 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4081 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4082 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4083 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4084 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4085 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4086 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4087 break;
4088
4089 default:
4090 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4091 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4092 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4093 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4094 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4095 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4096 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4097 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4098 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4099 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4100 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4101 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4102 break;
4103 }
4104
4105 break;
4106
4107 case right:
4108 switch(door)
4109 {
4110 case dWALL:
4111 case dBOMB:
4112 case dWALK:
4113 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4114 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4115 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4116 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4117 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4118 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4119 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4120 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4121 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4122 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4123 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4124 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4125 break;
4126
4127 default:
4128 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4129 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4130 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4131 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4132 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4133 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4134 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4135 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4136 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4137 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4138 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4139 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4140 break;
4141 }
4142
4143 break;
4144 }
4145 }
4146 void zmap::DoPutDoorCommand(int side, int door, bool force)
4147 {
4148 if(!force && screens[cursor.screen].door[side] == door)
4149 return;
4150 bool already_list = InListCommand();
4151 if(!already_list)
4152 StartListCommand();
4153 DoSetDoorCommand(cursor.screen,side,door);
4154 if(door != dNONE)
4155 {
4156 word data[176] = {0};
4157 byte cset[176] = {0};
4158 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4159 for(int q = 0; q < 176; ++q)
4160 if(data[q])
4161 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4162 }
4163 if(!already_list)
4164 FinishListCommand();
4165 }
4166 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4167 {
4168 if(screens[screen].door[side] == door)
4169 return;
4170
4171 screens[screen].door[side] = door;
4172 if(door != dNONE)
4173 {
4174 word data[176] = {0};
4175 byte cset[176] = {0};
4176 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4177 for(int q = 0; q < 176; ++q)
4178 if(data[q])
4179 {
4180 screens[screen].data[q] = data[q];
4181 screens[screen].cset[q] = cset[q];
4182 }
4183 }
4184 }
4185
4186 void list_command::execute()
4187 {
4188 for (auto command : commands)
4189 {
4190 command->execute();
4191 }
4192 }
4193
4194 void list_command::undo()
4195 {
4196 for (int i = commands.size() - 1; i >= 0; i--)
4197 {
4198 commands[i]->undo();
4199 }
4200 }
4201
4202 int list_command::size()
4203 {
4204 int s = 0;
4205 for (auto command : commands)
4206 {
4207 s += command->size();
4208 }
4209 return s;
4210 }
4211
4212 void set_combo_command::execute()
4213 {
4214 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4215 if (!scr_ptr) return;
4216
4217 if (combo != -1) scr_ptr->data[pos] = combo;
4218 scr_ptr->cset[pos] = cset;
4219 }
4220
4221 void set_combo_command::undo()
4222 {
4223 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4224 if(!mapscr_ptr) return;
4225 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4226 mapscr_ptr->cset[pos] = prev_cset;
4227 }
4228
4229 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4230 {
4231 std::array<int, 8> initd_arr;
4232 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4233
4234 return {
4235 .x = ffc.x,
4236 .y = ffc.y,
4237 .vx = ffc.vx,
4238 .vy = ffc.vy,
4239 .ax = ffc.ax,
4240 .ay = ffc.ay,
4241 .data = ffc.data,
4242 .cset = ffc.cset,
4243 .delay = ffc.delay,
4244 .link = ffc.link,
4245 .script = ffc.script,
4246 .tw = ffc.txsz,
4247 .th = ffc.tysz,
4248 .ew = ffc.hit_width,
4249 .eh = ffc.hit_height,
4250 .flags = ffc.flags,
4251 .initd = initd_arr,
4252 .layer = ffc.layer
4253 };
4254 }
4255
4256 void set_ffc_command::execute()
4257 {
4258 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4259 if(!mapscr_ptr) return;
4260
4261 mapscr_ptr->valid |= mVALID;
4262 mapscr_ptr->ffcs[i].x = data.x;
4263 mapscr_ptr->ffcs[i].y = data.y;
4264 mapscr_ptr->ffcs[i].vx = data.vx;
4265 mapscr_ptr->ffcs[i].vy = data.vy;
4266 mapscr_ptr->ffcs[i].ax = data.ax;
4267 mapscr_ptr->ffcs[i].ay = data.ay;
4268 mapscr_ptr->ffcs[i].data = data.data;
4269 mapscr_ptr->ffcs[i].cset = data.cset;
4270 mapscr_ptr->ffcs[i].delay = data.delay;
4271 mapscr_ptr->ffcs[i].link = data.link;
4272 mapscr_ptr->ffcs[i].script = data.script;
4273 mapscr_ptr->ffcs[i].flags = data.flags;
4274 mapscr_ptr->ffEffectWidth(i, data.ew);
4275 mapscr_ptr->ffEffectHeight(i, data.eh);
4276 mapscr_ptr->ffTileWidth(i, data.tw);
4277 mapscr_ptr->ffTileHeight(i, data.th);
4278 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4279 mapscr_ptr->ffcs[i].layer = data.layer;
4280 mapscr_ptr->ffcCountMarkDirty();
4281 mapscr_ptr->ffcs[i].updateSolid();
4282 }
4283
4284 void set_ffc_command::undo()
4285 {
4286 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4287 if(!mapscr_ptr) return;
4288
4289 mapscr_ptr->ffcs[i].x = prev_data.x;
4290 mapscr_ptr->ffcs[i].y = prev_data.y;
4291 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4292 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4293 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4294 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4295 mapscr_ptr->ffcs[i].data = prev_data.data;
4296 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4297 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4298 mapscr_ptr->ffcs[i].link = prev_data.link;
4299 mapscr_ptr->ffcs[i].script = prev_data.script;
4300 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4301 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4302 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4303 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4304 mapscr_ptr->ffTileHeight(i, prev_data.th);
4305 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4306 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4307 mapscr_ptr->ffcCountMarkDirty();
4308 mapscr_ptr->ffcs[i].updateSolid();
4309 }
4310
4311 void set_flag_command::execute()
4312 {
4313 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4314 if(!mapscr_ptr) return;
4315
4316 mapscr_ptr->valid |= mVALID;
4317 mapscr_ptr->sflag[pos] = flag;
4318 }
4319
4320 void set_flag_command::undo()
4321 {
4322 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4323 if(!mapscr_ptr) return;
4324 mapscr_ptr->sflag[pos] = prev_flag;
4325 }
4326
4327 void set_door_command::execute()
4328 {
4329 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4330 if(!mapscr_ptr) return;
4331
4332 mapscr_ptr->valid |= mVALID;
4333 mapscr_ptr->door[side] = door;
4334 }
4335
4336 void set_door_command::undo()
4337 {
4338 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4339 }
4340
4341 void set_dcs_command::execute()
4342 {
4343 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4344 if(!mapscr_ptr) return;
4345
4346 mapscr_ptr->valid |= mVALID;
4347 mapscr_ptr->door_combo_set = dcs;
4348 }
4349
4350 void set_dcs_command::undo()
4351 {
4352 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4353 }
4354
4355 void paste_screen_command::execute()
4356 {
4357 perform(screen.get());
4358 }
4359
4360 void paste_screen_command::undo()
4361 {
4362 if (prev_screens.size() > 1)
4363 {
4364 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4365 ASSERT(prev_screens.size() == 128);
4366 for (int i = 0; i < 128; i++)
4367 {
4368 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4369 // TODO: why not just this?
4370 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4371 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4372 }
4373 return;
4374 }
4375
4376 perform(prev_screens[0].get());
4377 }
4378
4379 int paste_screen_command::size()
4380 {
4381 return prev_screens.size() + 1;
4382 }
4383
4384 void paste_screen_command::perform(mapscr* to)
4385 {
4386 if (to)
4387 {
4388 switch (type) {
4389 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4390 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4391 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4392 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4393 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4394 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4395 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4396 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4397 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4398 case ScreenPartial: Map.Paste(*to, screen_index); break;
4399 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4400 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4401 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4402 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4403 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4404 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4405 }
4406 }
4407 else
4408 {
4409 Map.clearscr(screen_index);
4410 }
4411 refresh(rALL);
4412 }
4413
4414 void set_screen_command::execute()
4415 {
4416 if (screen)
4417 {
4418 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4419 }
4420 else
4421 {
4422 Map.clearscr(screen_index);
4423 }
4424 refresh(rALL);
4425 }
4426
4427 void set_screen_command::undo()
4428 {
4429 if (prev_screen)
4430 {
4431 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4432 }
4433 else
4434 {
4435 Map.clearscr(screen_index);
4436 }
4437 refresh(rALL);
4438 }
4439
4440 int set_screen_command::size()
4441 {
4442 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4443 }
4444
4445 static std::shared_ptr<list_command> current_list_command;
4446 void zmap::StartListCommand()
4447 {
4448 ASSERT(!current_list_command);
4449 current_list_command.reset(new list_command);
4450 }
4451
4452 void zmap::FinishListCommand()
4453 {
4454 if (current_list_command->commands.size() == 1)
4455 {
4456 undo_stack.push_back(current_list_command->commands[0]);
4457 }
4458 else if (current_list_command->commands.size() > 1)
4459 {
4460 undo_stack.push_back(current_list_command);
4461 }
4462 CapCommandHistory();
4463 current_list_command = nullptr;
4464 }
4465
4466 void zmap::RevokeListCommand()
4467 {
4468 current_list_command->undo();
4469 current_list_command = nullptr;
4470 }
4471
4472 bool zmap::InListCommand() const
4473 {
4474 return current_list_command ? true : false;
4475 }
4476
4477 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4478 {
4479 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4480 if (!skip_execute) command->execute();
4481 if (current_list_command)
4482 {
4483 current_list_command->commands.push_back(command);
4484 if (current_list_command->commands.size() == 1)
4485 {
4486 current_list_command->cursor = command->cursor;
4487 }
4488 }
4489 else
4490 {
4491 undo_stack.push_back(command);
4492 CapCommandHistory();
4493 }
4494 saved = false;
4495 }
4496
4497 void zmap::UndoCommand()
4498 {
4499 if (undo_stack.size() <= 0) return;
4500
4501 // If not currently looking at the associated screen, first change the view
4502 // and wait for the next call to actually undo this command.
4503 auto command = undo_stack.back();
4504 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4505 {
4506 setCursor(command.get()->cursor);
4507 return;
4508 }
4509
4510 command->undo();
4511 redo_stack.push(command);
4512 undo_stack.pop_back();
4513 saved = false;
4514 }
4515
4516 void zmap::RedoCommand()
4517 {
4518 if (redo_stack.size() <= 0) return;
4519
4520 // If not currently selected the associated screen, first change the cursor
4521 // and wait for the next call to actually execute this command.
4522 auto command = redo_stack.top();
4523 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4524 {
4525 setCursor(command.get()->cursor);
4526 return;
4527 }
4528
4529 command->execute();
4530 undo_stack.push_back(command);
4531 redo_stack.pop();
4532 saved = false;
4533 }
4534
4535 11 void zmap::ClearCommandHistory()
4536 {
4537 11 current_list_command = nullptr;
4538 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4539 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4540 11 }
4541
4542 // Extra amount is from mapscr's vectors.
4543 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4544 // Allow the undo system to use roughly 100 MB of memory.
4545 // This doesn't count the memory used by commands that don't store a mapscr,
4546 // but that should be negligible.
4547 12 static int max_command_size = 100e6 / size_of_mapscr;
4548 void zmap::CapCommandHistory()
4549 {
4550 int size;
4551 do
4552 {
4553 size = 0;
4554 for (auto command : undo_stack)
4555 {
4556 size += command->size();
4557 }
4558 if (size > max_command_size) undo_stack.pop_front();
4559 } while (size > max_command_size);
4560 }
4561
4562 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4563 {
4564 if (!pos.is_valid(cursor))
4565 return;
4566
4567 int map = cursor.map;
4568 int screen = cursor.viewscr + pos.screen_offset();
4569 if (!AbsoluteScr(map, screen))
4570 return;
4571
4572 if (CurrentLayer)
4573 {
4574 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4575 map = scr->layermap[CurrentLayer-1]-1;
4576 screen = scr->layerscreen[CurrentLayer-1];
4577 }
4578 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4579 }
4580
4581 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4582 {
4583 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4584 if (!mapscr_ptr) return;
4585
4586 std::shared_ptr<set_combo_command> command(new set_combo_command);
4587 command->cursor = cursor;
4588 command->map = map;
4589 command->scr = scr;
4590 command->pos = pos;
4591 command->combo = combo;
4592 command->cset = cset;
4593 command->prev_combo = mapscr_ptr->data[pos];
4594 command->prev_cset = mapscr_ptr->cset[pos];
4595 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4596 {
4597 // nothing to do...
4598 return;
4599 }
4600
4601 ExecuteCommand(command);
4602 }
4603
4604 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4605 {
4606 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4607 if(!mapscr_ptr) return;
4608
4609 mapscr_ptr->ensureFFC(i);
4610
4611 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4612
4613 std::array<int, 8> initd_arr;
4614 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4615
4616 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4617
4618 command->cursor = cursor;
4619 command->map = map;
4620 command->scr = scr;
4621 command->i = i;
4622 command->data = data;
4623 command->prev_data = prev_data;
4624 if (data == prev_data)
4625 {
4626 // nothing to do...
4627 return;
4628 }
4629
4630 ExecuteCommand(command);
4631 }
4632
4633 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4634 {
4635 if (!pos.is_valid(cursor))
4636 return;
4637
4638 int map = cursor.map;
4639 int screen = cursor.viewscr + pos.screen_offset();
4640 if (!AbsoluteScr(map, screen))
4641 return;
4642
4643 if (CurrentLayer)
4644 {
4645 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4646 map = scr->layermap[CurrentLayer-1]-1;
4647 screen = scr->layerscreen[CurrentLayer-1];
4648 }
4649 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4650 }
4651
4652 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4653 {
4654 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4655 if(!mapscr_ptr) return;
4656
4657 std::shared_ptr<set_flag_command> command(new set_flag_command);
4658 command->cursor = cursor;
4659 command->map = map;
4660 command->scr = scr;
4661 command->pos = pos;
4662 command->flag = flag;
4663 command->prev_flag = mapscr_ptr->sflag[pos];
4664 if (command->flag == command->prev_flag)
4665 {
4666 // nothing to do...
4667 return;
4668 }
4669
4670 ExecuteCommand(command);
4671 }
4672
4673 void zmap::DoSetDoorCommand(int scr, int side, int door)
4674 {
4675 if(screens[scr].door[side] == door)
4676 return;
4677 std::shared_ptr<set_door_command> command(new set_door_command);
4678 command->cursor = cursor;
4679 command->side = side;
4680 command->door = door;
4681 command->prev_door = screens[scr].door[side];
4682
4683 ExecuteCommand(command);
4684 }
4685 void zmap::DoSetDCSCommand(int dcs)
4686 {
4687 if(screens[cursor.screen].door_combo_set == dcs)
4688 return;
4689 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4690 command->cursor = cursor;
4691 command->dcs = dcs;
4692 command->prev_dcs = screens[cursor.screen].door_combo_set;
4693
4694 ExecuteCommand(command);
4695 }
4696
4697 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4698 {
4699 if (screen == -1)
4700 screen = cursor.screen;
4701
4702 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4703 command->cursor = cursor;
4704 command->type = type;
4705 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4706 command->screen_index = screen;
4707
4708 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4709 {
4710 for (int i=0; i < 128; i++)
4711 {
4712 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4713 }
4714 }
4715 else
4716 {
4717 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4718 }
4719
4720 ExecuteCommand(command);
4721 }
4722
4723 void zmap::DoClearScreenCommand(int screen)
4724 {
4725 std::shared_ptr<set_screen_command> command(new set_screen_command);
4726 command->cursor = cursor;
4727 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4728 command->screen = std::shared_ptr<mapscr>(nullptr);
4729 command->screen_index = screen;
4730
4731 ExecuteCommand(command);
4732 }
4733
4734 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4735 {
4736 std::shared_ptr<set_screen_command> command(new set_screen_command);
4737 command->cursor = cursor;
4738 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4739 Template(floorcombo, floorcset, screen);
4740 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4741
4742 ExecuteCommand(command, true);
4743 }
4744
4745 void zmap::Copy(int scr)
4746 {
4747 if(screens[scr].valid&mVALID)
4748 {
4749 copy_mapscr(&copymapscr, &screens[scr]);
4750 //copymapscr=screens[scr];
4751 can_paste=true;
4752 copymap=cursor.map;
4753 copyscr=scr;
4754 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4755 copyffc = -1;
4756 }
4757 }
4758
4759 void zmap::CopyFFC(int32_t screen, int32_t n)
4760 {
4761 if(screens[screen].valid&mVALID)
4762 {
4763 copy_mapscr(&copymapscr, &screens[screen]);
4764 // Can't paste the screen itself
4765 can_paste = false;
4766 copymap=cursor.map;
4767 copyscr=screen;
4768 copyffc = n;
4769 }
4770 }
4771
4772 void zmap::Paste(const mapscr& copymapscr, int screen)
4773 {
4774 if(can_paste)
4775 {
4776 if(!(screens[screen].valid&mVALID))
4777 {
4778 screens[screen].valid |= mVALID;
4779 screens[screen].color = copymapscr.color;
4780 }
4781
4782 screens[screen].door_combo_set = copymapscr.door_combo_set;
4783
4784 for(int32_t i=0; i<4; i++)
4785 {
4786 screens[screen].door[i]=copymapscr.door[i];
4787 }
4788
4789 for(int32_t i=0; i<176; i++)
4790 {
4791 screens[screen].data[i] = copymapscr.data[i];
4792 screens[screen].cset[i] = copymapscr.cset[i];
4793 screens[screen].sflag[i] = copymapscr.sflag[i];
4794 }
4795
4796 refresh_color();
4797
4798 saved=false;
4799 }
4800 }
4801
4802 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4803 {
4804 if(can_paste)
4805 {
4806 screens[screen].undercombo = copymapscr.undercombo;
4807 screens[screen].undercset = copymapscr.undercset;
4808 saved=false;
4809 }
4810 }
4811
4812 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4813 {
4814 if(can_paste)
4815 {
4816 for(int32_t i=0; i<128; i++)
4817 {
4818 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4819 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4820 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4821 }
4822
4823 saved=false;
4824 }
4825 }
4826
4827 // TODO const mapscr& copymapscr
4828 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4829 {
4830 if(can_paste)
4831 {
4832 screens[screen].ffcs = copymapscr.ffcs;
4833 screens[screen].ffcCountMarkDirty();
4834 saved=false;
4835 }
4836 }
4837
4838 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4839 {
4840 if(can_paste)
4841 {
4842 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4843
4844 for(int32_t i=0; i<4; i++)
4845 {
4846 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4847 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4848 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4849 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4850 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4851 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4852 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4853 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4854 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4855 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4856 }
4857
4858 saved=false;
4859 }
4860 }
4861
4862 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4863 {
4864 if(can_paste)
4865 {
4866 screens[screen].csensitive = copymapscr.csensitive;
4867 screens[screen].oceansfx = copymapscr.oceansfx;
4868 screens[screen].bosssfx = copymapscr.bosssfx;
4869 screens[screen].secretsfx = copymapscr.secretsfx;
4870 screens[screen].holdupsfx = copymapscr.holdupsfx;
4871 screens[screen].flags = copymapscr.flags;
4872 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4874 screens[screen].flags3 = copymapscr.flags3;
4875 screens[screen].flags4 = copymapscr.flags4;
4876 screens[screen].flags5 = copymapscr.flags5;
4877 screens[screen].flags6 = copymapscr.flags6;
4878 screens[screen].flags7 = copymapscr.flags7;
4879 screens[screen].flags8 = copymapscr.flags8;
4880 screens[screen].flags9 = copymapscr.flags9;
4881 screens[screen].flags10 = copymapscr.flags10;
4882 screens[screen].flags11 = copymapscr.flags11;
4883 screens[screen].item = copymapscr.item;
4884 screens[screen].hasitem = copymapscr.hasitem;
4885 screens[screen].itemx = copymapscr.itemx;
4886 screens[screen].itemy = copymapscr.itemy;
4887 screens[screen].nextmap = copymapscr.nextmap;
4888 screens[screen].nextscr = copymapscr.nextscr;
4889 screens[screen].nocarry = copymapscr.nocarry;
4890 screens[screen].noreset = copymapscr.noreset;
4891 screens[screen].exstate_reset = copymapscr.exstate_reset;
4892 screens[screen].exstate_carry = copymapscr.exstate_carry;
4893 screens[screen].path[0] = copymapscr.path[0];
4894 screens[screen].path[1] = copymapscr.path[1];
4895 screens[screen].path[2] = copymapscr.path[2];
4896 screens[screen].path[3] = copymapscr.path[3];
4897 screens[screen].pattern = copymapscr.pattern;
4898 screens[screen].exitdir = copymapscr.exitdir;
4899 screens[screen].screen_midi = copymapscr.screen_midi;
4900 screens[screen].stairx = copymapscr.stairx;
4901 screens[screen].stairy = copymapscr.stairy;
4902 screens[screen].timedwarptics = copymapscr.timedwarptics;
4903 saved=false;
4904 }
4905 }
4906
4907 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4908 {
4909 if(can_paste)
4910 {
4911 screens[screen].warpreturnc = copymapscr.warpreturnc;
4912 screens[screen].warparrivalx = copymapscr.warparrivalx;
4913 screens[screen].warparrivaly = copymapscr.warparrivaly;
4914
4915 for(int32_t i=0; i<4; i++)
4916 {
4917 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4918 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4919 }
4920
4921 saved=false;
4922 }
4923 }
4924
4925 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4926 {
4927 if(can_paste)
4928 {
4929 for(int32_t i=0; i<4; i++)
4930 screens[screen].door[i] = copymapscr.door[i];
4931
4932 screens[screen].door_combo_set = copymapscr.door_combo_set;
4933 saved=false;
4934 }
4935 }
4936
4937 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4938 {
4939 if(can_paste)
4940 {
4941 for(int32_t i=0; i<6; i++)
4942 {
4943 screens[screen].layermap[i] = copymapscr.layermap[i];
4944 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4945 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4946 }
4947
4948 saved=false;
4949 }
4950 }
4951
4952 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4953 {
4954 if(can_paste)
4955 {
4956 screens[screen].room = copymapscr.room;
4957 screens[screen].catchall = copymapscr.catchall;
4958 saved=false;
4959 }
4960 }
4961
4962 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4963 {
4964 if(can_paste)
4965 {
4966 screens[screen].guy = copymapscr.guy;
4967 screens[screen].guytile = copymapscr.guytile;
4968 screens[screen].guycs = copymapscr.guycs;
4969 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4970 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4971 screens[screen].str = copymapscr.str;
4972 saved=false;
4973 }
4974 }
4975
4976 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4977 {
4978 if(can_paste)
4979 {
4980 screens[screen].color = copymapscr.color;
4981 screens[screen].valid|=mVALID;
4982 refresh_color();
4983
4984 saved=false;
4985 }
4986 }
4987
4988 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4989 {
4990 if(can_paste)
4991 {
4992 copy_mapscr(&screens[screen], &copymapscr);
4993 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4994 screens[screen].valid|=mVALID;
4995
4996 refresh_color();
4997
4998 saved=false;
4999 }
5000 }
5001
5002
5003 void zmap::PasteToAll(const mapscr& copymapscr)
5004 {
5005 if(can_paste)
5006 {
5007 for(int32_t x=0; x<128; x++)
5008 {
5009 if(!(screens[x].valid&mVALID))
5010 {
5011 screens[x].valid |= mVALID;
5012 screens[x].color = copymapscr.color;
5013 }
5014
5015 for(int32_t i=0; i<176; i++)
5016 {
5017 screens[x].data[i] = copymapscr.data[i];
5018 screens[x].cset[i] = copymapscr.cset[i];
5019 screens[x].sflag[i] = copymapscr.sflag[i];
5020 }
5021 }
5022
5023 refresh_color();
5024
5025 saved=false;
5026 }
5027 }
5028
5029 void zmap::PasteAllToAll(const mapscr& copymapscr)
5030 {
5031 if(can_paste)
5032 {
5033 for(int32_t x=0; x<128; x++)
5034 {
5035 copy_mapscr(&screens[x], &copymapscr);
5036 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5037 //screens[x]=copymapscr;
5038 }
5039
5040 refresh_color();
5041
5042 saved=false;
5043 }
5044 }
5045
5046 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5047 {
5048 if(can_paste)
5049 {
5050 for(int32_t i=0; i<10; i++)
5051 screens[screen].enemy[i]=copymapscr.enemy[i];
5052 }
5053 }
5054
5055 void zmap::setCopyFFC(int32_t n)
5056 {
5057 copyffc = n;
5058 }
5059
5060 void zmap::update_combo_cycling()
5061 {
5062 if(!prv_mode||!prv_cmbcycle)
5063 {
5064 return;
5065 }
5066
5067 int32_t x;
5068 int32_t newdata[176];
5069 int32_t newcset[176];
5070 bool restartanim[MAXCOMBOS] = {0};
5071
5072 for(int32_t i=0; i<176; i++)
5073 {
5074 newdata[i]=-1;
5075 newcset[i]=-1;
5076
5077 x=prvscr.data[i];
5078
5079 //time to restart
5080 if((combobuf[x].aclk>=combobuf[x].speed) &&
5081 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5082 combobuf[x].can_cycle())
5083 {
5084 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5085 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5086
5087 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5088 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5089 int32_t c = newdata[i];
5090
5091 if(combobuf[c].animflags & AF_CYCLE)
5092 {
5093 restartanim[c]=true;
5094 }
5095 }
5096 }
5097
5098 for(int32_t i=0; i<176; i++)
5099 {
5100 x=prvscr.data[i];
5101
5102 //time to restart
5103 if((combobuf[x].aclk>=combobuf[x].speed) &&
5104 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5105 combobuf[x].can_cycle())
5106 {
5107 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5108 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5109
5110 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5111 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5112 int32_t c = newdata[i];
5113
5114 if(combobuf[c].animflags & AF_CYCLE)
5115 {
5116 restartanim[c]=true;
5117 }
5118 }
5119 }
5120
5121 for(int32_t i=0; i<176; i++)
5122 {
5123 if(newdata[i]==-1)
5124 continue;
5125
5126 prvscr.data[i]=newdata[i];
5127 prvscr.cset[i]=newcset[i];
5128 }
5129
5130 word maxffc = prvscr.numFFC();
5131 for(word i=0; i<maxffc; i++)
5132 {
5133 ffcdata& ffc = prvscr.ffcs[i];
5134 newcombo const& cmb = combobuf[ffc.data];
5135
5136 //time to restart
5137 if((cmb.aclk>=cmb.speed) &&
5138 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5139 cmb.can_cycle())
5140 {
5141 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5142 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5143
5144 if(!(cmb.animflags & AF_CYCLENOCSET))
5145 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5146
5147 if(combobuf[ffc.data].animflags & AF_CYCLE)
5148 {
5149 restartanim[ffc.data]=true;
5150 }
5151 prvscr.ffcs[i].data = ffc.data;
5152 prvscr.ffcs[i].cset=ffc.cset;
5153 }
5154 }
5155
5156
5157 if(get_qr(qr_CMBCYCLELAYERS))
5158 {
5159 for(int32_t j=0; j<6; j++)
5160 {
5161 if(!prvlayers[j].valid)
5162 continue;
5163
5164 for(int32_t i=0; i<176; i++)
5165 {
5166 newdata[i]=-1;
5167 newcset[i]=-1;
5168
5169 x=(prvlayers[j]).data[i];
5170
5171 //time to restart
5172 if((combobuf[x].aclk>=combobuf[x].speed) &&
5173 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5174 combobuf[x].can_cycle())
5175 {
5176 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5177 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5178
5179 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5180 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5181 int32_t c = newdata[i];
5182
5183 if(combobuf[c].animflags & AF_CYCLE)
5184 {
5185 restartanim[c]=true;
5186 }
5187 }
5188 }
5189
5190 for(int32_t i=0; i<176; i++)
5191 {
5192 x=(prvlayers[j]).data[i];
5193
5194 //time to restart
5195 if((combobuf[x].aclk>=combobuf[x].speed) &&
5196 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5197 combobuf[x].can_cycle())
5198 {
5199 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5200 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5201
5202 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5203 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5204 int32_t c = newdata[i];
5205
5206 if(combobuf[c].animflags & AF_CYCLE)
5207 {
5208 restartanim[c]=true;
5209 }
5210 }
5211 }
5212
5213 for(int32_t i=0; i<176; i++)
5214 {
5215 if(newdata[i]==-1)
5216 continue;
5217
5218 prvlayers[j].data[i]=newdata[i];
5219 prvlayers[j].cset[i]=newcset[i];
5220 }
5221 }
5222 }
5223
5224 for(int32_t i=0; i<MAXCOMBOS; i++)
5225 {
5226 if(restartanim[i])
5227 {
5228 combobuf[i].tile = combobuf[i].o_tile;
5229 combobuf[i].cur_frame=0;
5230 combobuf[i].aclk = 0;
5231 }
5232 }
5233 }
5234
5235 void zmap::update_freeform_combos()
5236 {
5237 if(!prv_mode||!prv_cmbcycle)
5238 {
5239 return;
5240 }
5241
5242 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5243 word maxffc = prvscr.numFFC();
5244 for(int32_t i=0; i<maxffc; i++)
5245 {
5246 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5247 {
5248 for(int32_t j=0; j<maxffc; j++)
5249 {
5250 if(i!=j)
5251 {
5252 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5253 {
5254 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5255 {
5256 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5257 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5258 {
5259 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5260 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5261 if(prvscr.ffcs[j].flags&ffc_changethis)
5262 {
5263 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5264 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5265 }
5266
5267 if(prvscr.ffcs[j].flags&ffc_changenext)
5268 prvscr.ffcs[i].data += 1;
5269
5270 if(prvscr.ffcs[j].flags&ffc_changeprev)
5271 prvscr.ffcs[i].data -= 1;
5272
5273 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5274 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5275 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5276
5277 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5278 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5279 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5280 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5281
5282 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5283 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5284 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5285 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5286 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5287
5288 if(prvscr.ffcs[i].flags&ffc_carryover)
5289 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5290 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5291
5292 prvscr.ffcs[i].flags&=~ffc_changer;
5293 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5294 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5295
5296 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5297 {
5298 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5299 }
5300
5301 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5302 {
5303 int32_t k=0;
5304
5305 if(prvscr.ffcs[j].flags&ffc_swapnext)
5306 k=j<(MAXFFCS-1)?j+1:0;
5307
5308 if(prvscr.ffcs[j].flags&ffc_swapprev)
5309 k=j>0?j-1:(MAXFFCS-1);
5310
5311 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5312 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5313 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5314 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5315 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5316 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5317 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5318 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5319 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5320 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5321 }
5322 }
5323 }
5324 }
5325 }
5326 }
5327
5328 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5329 {
5330 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5331 {
5332 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5333 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5334 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5335 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5336 }
5337 else
5338 {
5339 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5340 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5341 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5342 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5343 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5344 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5345
5346 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5347 {
5348 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5349
5350 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5351
5352 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5353
5354 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5355 }
5356 }
5357 }
5358 else
5359 {
5360 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5361 prvscr.ffcs[i].delay--;
5362 }
5363
5364 if(prvscr.ffcs[i].x<-32)
5365 {
5366 if(prvscr.flags6&fWRAPAROUNDFF)
5367 {
5368 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5369 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5370 }
5371 else
5372 {
5373 prvscr.ffcs[i].data = 0;
5374 prvscr.ffcs[i].flags&=~ffc_carryover;
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].y<-32)
5379 {
5380 if(prvscr.flags6&fWRAPAROUNDFF)
5381 {
5382 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5383 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5384 }
5385 else
5386 {
5387 prvscr.ffcs[i].data = 0;
5388 prvscr.ffcs[i].flags&=~ffc_carryover;
5389 }
5390 }
5391
5392 if(prvscr.ffcs[i].x>=288)
5393 {
5394 if(prvscr.flags6&fWRAPAROUNDFF)
5395 {
5396 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5397 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5398 }
5399 else
5400 {
5401 prvscr.ffcs[i].data = 0;
5402 prvscr.ffcs[i].flags&=~ffc_carryover;
5403 }
5404 }
5405
5406 if(prvscr.ffcs[i].y>=208)
5407 {
5408 if(prvscr.flags6&fWRAPAROUNDFF)
5409 {
5410 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5411 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5412 }
5413 else
5414 {
5415 prvscr.ffcs[i].data = 0;
5416 prvscr.ffcs[i].flags&=~ffc_carryover;
5417 }
5418 }
5419
5420 }
5421 }
5422 }
5423
5424 void zmap::goto_dmapscr(int dmap, int scr)
5425 {
5426 setCurrMap(DMaps[dmap].map);
5427 setCurrScr(scr+DMaps[dmap].xoff);
5428 }
5429 void zmap::goto_mapscr(int map, int scr)
5430 {
5431 setCurrMap(map);
5432 setCurrScr(scr);
5433 }
5434
5435 void zmap::dowarp(int32_t type, int32_t index)
5436 {
5437 set_warpback();
5438 if(type==0)
5439 {
5440
5441 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5442 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5443
5444 switch(screens[cursor.screen].tilewarptype[index])
5445 {
5446 case wtCAVE:
5447 case wtNOWARP:
5448 break;
5449
5450 default:
5451 goto_dmapscr(dmap, scr);
5452 break;
5453 }
5454 }
5455 else if(type==1)
5456 {
5457 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5458 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5459
5460 switch(screens[cursor.screen].sidewarptype[index])
5461 {
5462 case wtCAVE:
5463 case wtNOWARP:
5464 break;
5465
5466 default:
5467 goto_dmapscr(dmap, scr);
5468 break;
5469 }
5470 }
5471 }
5472
5473 extern int32_t prv_twon;
5474
5475 void zmap::prv_dowarp(int32_t type, int32_t index)
5476 {
5477 if(type==0)
5478 {
5479
5480 int32_t dmap=prvscr.tilewarpdmap[index];
5481 int32_t scr=prvscr.tilewarpscr[index];
5482
5483 switch(prvscr.tilewarptype[index])
5484 {
5485 case wtCAVE:
5486 case wtNOWARP:
5487 break;
5488
5489 default:
5490 //setCurrMap(DMaps[dmap].map);
5491 //setCurrScr(scr+DMaps[dmap].xoff);
5492 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5493 refresh_color();
5494 //prv_cmbcycle=0;
5495 break;
5496 }
5497 }
5498 else if(type==1)
5499 {
5500 int32_t dmap=prvscr.sidewarpdmap[index];
5501 int32_t scr=prvscr.sidewarpscr[index];
5502
5503 switch(prvscr.sidewarptype[index])
5504 {
5505 case wtCAVE:
5506 case wtNOWARP:
5507 break;
5508
5509 default:
5510 //setCurrMap(DMaps[dmap].map);
5511 //setCurrScr(scr+DMaps[dmap].xoff);
5512 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5513 refresh_color();
5514 //prv_cmbcycle=0;
5515 break;
5516 }
5517 }
5518
5519 if(prv_twon)
5520 {
5521 prv_time=get_prvscr()->timedwarptics;
5522 }
5523 }
5524
5525 void zmap::dowarp2(int32_t ring,int32_t index)
5526 {
5527 set_warpback();
5528 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5529 }
5530
5531 void zmap::set_warpback()
5532 {
5533 warpbackmap = cursor.map;
5534 warpbackscreen = cursor.screen;
5535 }
5536 bool zmap::has_warpback()
5537 {
5538 return warpbackmap && warpbackscreen
5539 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5540 }
5541 void zmap::warpback()
5542 {
5543 if(!has_warpback())
5544 return;
5545
5546 int m = cursor.map, s = cursor.screen;
5547 goto_mapscr(*warpbackmap, *warpbackscreen);
5548 warpbackmap = m;
5549 warpbackscreen = s;
5550 }
5551
5552 bool save_msgstrs(const char *path)
5553 {
5554 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5555
5556 if(!f)
5557 {
5558 return false;
5559 }
5560
5561 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5562 {
5563 pack_fclose(f);
5564 return true;
5565 }
5566
5567 pack_fclose(f);
5568 return false;
5569 }
5570
5571 1 bool save_strings_tsv(const char *path)
5572 {
5573 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5574
5575
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5576 {
5577 return false;
5578 }
5579
5580
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5581 {
5582 1 pack_fclose(f);
5583 1 return true;
5584 }
5585
5586 pack_fclose(f);
5587 return false;
5588 1 }
5589
5590 bool save_msgstrs_text(const char *path)
5591 {
5592 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5593
5594 if(!f)
5595 {
5596 return false;
5597 }
5598
5599 if(writestrings_text(f)==0)
5600 {
5601 pack_fclose(f);
5602 return true;
5603 }
5604
5605 pack_fclose(f);
5606 return false;
5607 }
5608
5609 bool load_msgstrs(const char *path, int32_t startstring)
5610 {
5611 //these are here to bypass compiler warnings about unused arguments
5612 startstring=startstring;
5613
5614 dword section_id;
5615 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5616
5617 if(!f)
5618 {
5619 return false;
5620 }
5621
5622 if(!p_mgetl(&section_id,f))
5623 {
5624 return false;
5625 }
5626
5627 if(section_id==ID_STRINGS)
5628 {
5629 if(readstrings(f, &header)==0)
5630 {
5631 pack_fclose(f);
5632 return true;
5633 }
5634 else
5635 {
5636 pack_fclose(f);
5637 return false;
5638 }
5639 }
5640
5641 pack_fclose(f);
5642 return false;
5643 }
5644
5645 bool load_strings_tsv(const char *path)
5646 {
5647 try
5648 {
5649 parse_strings_tsv(util::read_text_file(path));
5650 }
5651 catch (std::exception& ex)
5652 {
5653 InfoDialog("Import .tsv Error", ex.what()).show();
5654 return false;
5655 }
5656 return true;
5657 }
5658
5659 bool save_pals(const char *path)
5660 {
5661 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5662
5663 if(!f)
5664 {
5665 return false;
5666 }
5667
5668 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5669 {
5670 pack_fclose(f);
5671 return true;
5672 }
5673
5674 pack_fclose(f);
5675 return false;
5676 }
5677
5678 bool load_pals(const char *path, int32_t startcset)
5679 {
5680 dword section_id;
5681 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5682
5683 if(!f)
5684 {
5685 return false;
5686 }
5687
5688 if(!p_mgetl(&section_id,f))
5689 {
5690 return false;
5691 }
5692
5693 if(section_id==ID_CSETS)
5694 {
5695 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5696 {
5697 pack_fclose(f);
5698 loadlvlpal(Color);
5699 return true;
5700 }
5701 else
5702 {
5703 pack_fclose(f);
5704 return false;
5705 }
5706 }
5707
5708 return false;
5709 }
5710
5711 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5712 bool save_guys(const char *path)
5713 {
5714 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5715
5716 if(!f)
5717 {
5718 return false;
5719 }
5720
5721 /*
5722 int32_t id = ID_GUYS;
5723 if(!p_mputl(id,f))
5724 {
5725 return false;
5726 }
5727 */
5728
5729 zquestheader h;
5730 h.zelda_version = 0x250;
5731 h.build = 21;
5732
5733 if(writeguys(f, &h)==0)
5734 {
5735 pack_fclose(f);
5736 return true;
5737 }
5738
5739 pack_fclose(f);
5740 return false;
5741 }
5742
5743 bool load_guys(const char *path)
5744 {
5745 dword section_id;
5746 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5747
5748 if(!f)
5749 {
5750 return false;
5751 }
5752
5753 if(!p_mgetl(&section_id,f))
5754 {
5755 pack_fclose(f);
5756 return false;
5757 }
5758
5759 zquestheader h;
5760 h.zelda_version = 0x250;
5761 h.build = 21;
5762
5763 if(section_id==ID_GUYS)
5764 {
5765 if(readguys(f, &h)==0)
5766 {
5767 pack_fclose(f);
5768 return true;
5769 }
5770 }
5771
5772 pack_fclose(f);
5773 return false;
5774 }
5775
5776
5777 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5778 bool save_combo_alias(const char *path)
5779 {
5780 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5781
5782 if(!f)
5783 {
5784 return false;
5785 }
5786
5787 zquestheader h;
5788 h.zelda_version = 0x250;
5789 h.build = 21;
5790
5791 if(writecomboaliases(f, 0, 0)==0)
5792 {
5793 pack_fclose(f);
5794 return true;
5795 }
5796
5797 pack_fclose(f);
5798 return false;
5799 }
5800
5801 bool load_combo_alias(const char *path)
5802 {
5803 dword section_id;
5804 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5805
5806 if(!f)
5807 {
5808 return false;
5809 }
5810
5811 if(!p_mgetl(&section_id,f))
5812 {
5813 pack_fclose(f);
5814 return false;
5815 }
5816
5817 zquestheader h;
5818 h.zelda_version = 0x250;
5819 h.build = 21;
5820
5821 if(section_id==ID_COMBOALIASES)
5822 {
5823 if(readcomboaliases(f, &h, 0, 0)==0)
5824 {
5825 pack_fclose(f);
5826 return true;
5827 }
5828 }
5829
5830 pack_fclose(f);
5831 return false;
5832 }
5833
5834 bool load_zgp(const char *path)
5835 {
5836 dword section_id;
5837 word section_version;
5838 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5839
5840 if(!f)
5841 return false;
5842
5843 if(!p_mgetl(&section_id,f))
5844 {
5845 pack_fclose(f);
5846 return false;
5847 }
5848
5849 if(section_id!=ID_GRAPHICSPACK)
5850 {
5851 pack_fclose(f);
5852 return false;
5853 }
5854
5855 //section version info
5856 if(!p_igetw(&section_version,f))
5857 {
5858 return 2;
5859 }
5860
5861 if(!read_deprecated_section_cversion(f))
5862 {
5863 return 3;
5864 }
5865
5866 //tiles
5867 if(!p_mgetl(&section_id,f))
5868 {
5869 pack_fclose(f);
5870 return false;
5871 }
5872
5873 if(section_id==ID_TILES)
5874 {
5875 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5876 {
5877 pack_fclose(f);
5878 init_tiles(true, &header);
5879 return false;
5880 }
5881 }
5882 else
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 //combos
5889 if(!p_mgetl(&section_id,f))
5890 {
5891 pack_fclose(f);
5892 return false;
5893 }
5894
5895 if(section_id==ID_COMBOS)
5896 {
5897 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5898 {
5899 pack_fclose(f);
5900 return false;
5901 }
5902 }
5903 else
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 //palettes
5910 if(!p_mgetl(&section_id,f))
5911 {
5912 pack_fclose(f);
5913 return false;
5914 }
5915
5916 if(section_id==ID_CSETS)
5917 {
5918 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5919 {
5920 pack_fclose(f);
5921 return false;
5922 }
5923 }
5924 else
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929
5930 //items
5931 if(!p_mgetl(&section_id,f))
5932 {
5933 pack_fclose(f);
5934 return false;
5935 }
5936
5937 if(section_id==ID_ITEMS)
5938 {
5939 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5940 {
5941 pack_fclose(f);
5942 return false;
5943 }
5944 }
5945 else
5946 {
5947 pack_fclose(f);
5948 return false;
5949 }
5950
5951 //weapons
5952 if(!p_mgetl(&section_id,f))
5953 {
5954 pack_fclose(f);
5955 return false;
5956 }
5957
5958 if(section_id==ID_WEAPONS)
5959 {
5960 if(readweapons(f, &header)!=0)
5961 {
5962 pack_fclose(f);
5963 return false;
5964 }
5965 }
5966 else
5967 {
5968 pack_fclose(f);
5969 return false;
5970 }
5971
5972 //read the triforce pieces info and make sure it worked
5973 //really do this?
5974
5975 //read the game icons info and make sure it worked
5976 if(!p_mgetl(&section_id,f))
5977 {
5978 pack_fclose(f);
5979 return false;
5980 }
5981
5982 if(section_id==ID_ICONS)
5983 {
5984 if(readgameicons(f, &header, &QMisc)!=0)
5985 {
5986 pack_fclose(f);
5987 return false;
5988 }
5989 }
5990 else
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 //read the misc colors info and map styles info and make sure it worked
5997 if(!p_mgetl(&section_id,f))
5998 {
5999 pack_fclose(f);
6000 return false;
6001 }
6002
6003 if(section_id==ID_COLORS)
6004 {
6005 if(readmisccolors(f, &header, &QMisc)!=0)
6006 {
6007 pack_fclose(f);
6008 return false;
6009 }
6010 }
6011 else
6012 {
6013 pack_fclose(f);
6014 return false;
6015 }
6016
6017 //read the door combo sets and make sure it worked
6018 if(!p_mgetl(&section_id,f))
6019 {
6020 pack_fclose(f);
6021 return false;
6022 }
6023
6024 if(section_id==ID_DOORS)
6025 {
6026 if(readdoorcombosets(f, &header)!=0)
6027 {
6028 pack_fclose(f);
6029 return false;
6030 }
6031 }
6032 else
6033 {
6034 pack_fclose(f);
6035 return false;
6036 }
6037
6038 //read the template screens and make sure it worked
6039 //really do this?
6040
6041 //yay! it worked! close the file and say everything was ok.
6042 loadlvlpal(Color);
6043 setup_combo_animations();
6044 setup_combo_animations2();
6045 pack_fclose(f);
6046 return true;
6047 }
6048
6049 bool save_zgp(const char *path)
6050 {
6051 reset_combo_animations();
6052 reset_combo_animations2();
6053
6054 //open the file
6055 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6056
6057 if(!f)
6058 return false;
6059
6060 dword section_id=ID_GRAPHICSPACK;
6061 dword section_version=V_GRAPHICSPACK;
6062
6063 //section id
6064 if(!p_mputl(section_id,f))
6065 {
6066 return 1;
6067 }
6068
6069 //section version info
6070 if(!p_iputw(section_version,f))
6071 {
6072 return 2;
6073 }
6074
6075 if(!write_deprecated_section_cversion(section_version,f))
6076 {
6077 return 3;
6078 }
6079
6080 //tiles
6081 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 //combos
6088 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6089 {
6090 pack_fclose(f);
6091 return false;
6092 }
6093
6094 //palettes
6095 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6096 {
6097 pack_fclose(f);
6098 return false;
6099 }
6100
6101 //items
6102 if(writeitems(f, &header)!=0)
6103 {
6104 pack_fclose(f);
6105 return false;
6106 }
6107
6108 //weapons
6109 if(writeweapons(f, &header)!=0)
6110 {
6111 pack_fclose(f);
6112 return false;
6113 }
6114
6115 //write the triforce pieces info and make sure it worked
6116 //really do this?
6117
6118 //write the game icons info and make sure it worked
6119 if(writegameicons(f, &header)!=0)
6120 {
6121 pack_fclose(f);
6122 return false;
6123 }
6124
6125 //write the misc colors info and map styles info and make sure it worked
6126 if(writemisccolors(f, &header)!=0)
6127 {
6128 pack_fclose(f);
6129 return false;
6130 }
6131
6132 //write the door combo sets and make sure it worked
6133 if(writedoorcombosets(f, &header)!=0)
6134 {
6135 pack_fclose(f);
6136 return false;
6137 }
6138
6139 //write the template screens and make sure it worked
6140 //really do this?
6141
6142 pack_fclose(f);
6143 return true;
6144 }
6145
6146 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6147 {
6148 //open the file
6149 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6150
6151 if(!f)
6152 return false;
6153
6154 dword section_id=ID_SUBSCREEN;
6155 dword s_version=V_SUBSCREEN;
6156
6157 if(!p_mputl(section_id,f))
6158 {
6159 pack_fclose(f);
6160 return false;
6161 }
6162
6163 if(!p_iputw(s_version,f))
6164 {
6165 pack_fclose(f);
6166 return false;
6167 }
6168
6169 if(!write_deprecated_section_cversion(s_version,f))
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 if(savefrom.write(f))
6176 {
6177 pack_fclose(f);
6178 return false;
6179 }
6180
6181 pack_fclose(f);
6182 return true;
6183 }
6184
6185 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6186 {
6187 //open the file
6188 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6189
6190 if(!f)
6191 return false;
6192
6193 dword section_id;
6194 dword s_version;
6195
6196 if(!p_mgetl(&section_id,f))
6197 {
6198 pack_fclose(f);
6199 return false;
6200 }
6201
6202 if(section_id!=ID_SUBSCREEN)
6203 {
6204 pack_fclose(f);
6205 return false;
6206 }
6207
6208 if(!p_igetw(&s_version,f))
6209 {
6210 pack_fclose(f);
6211 return false;
6212 }
6213
6214 if (s_version > V_SUBSCREEN)
6215 return qe_version;
6216
6217 if(!read_deprecated_section_cversion(f))
6218 {
6219 pack_fclose(f);
6220 return false;
6221 }
6222
6223 if(s_version < 8)
6224 {
6225 subscreen_group g;
6226 memset(&g,0,sizeof(subscreen_group));
6227 if(read_one_old_subscreen(f,&g,s_version)!=0)
6228 {
6229 pack_fclose(f);
6230 return false;
6231 }
6232 if(g.ss_type != loadto.sub_type)
6233 {
6234 pack_fclose(f);
6235 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6236 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6237 return false;
6238 }
6239 loadto.clear();
6240 if(g.objects[0].type != ssoNULL)
6241 loadto.load_old(g);
6242 }
6243 else
6244 {
6245 ZCSubscreen tmp = ZCSubscreen();
6246 if (tmp.read(f, s_version))
6247 {
6248 pack_fclose(f);
6249 return false;
6250 }
6251 if(tmp.sub_type != loadto.sub_type)
6252 {
6253 pack_fclose(f);
6254 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6255 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6256 return false;
6257 }
6258 loadto.clear();
6259 loadto = tmp;
6260 }
6261
6262 pack_fclose(f);
6263 return true;
6264 }
6265
6266 bool setMapCount2(int32_t c)
6267 {
6268 int32_t oldmapcount=map_count;
6269 int32_t cur_map=Map.getCurrMap();
6270
6271 bound(c,1,MAXMAPS);
6272 map_count=c;
6273
6274 try
6275 {
6276 TheMaps.resize(c*MAPSCRS);
6277 Map.force_refr_pointer();
6278 map_infos.resize(c);
6279 }
6280 catch(...)
6281 {
6282 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6283 return false;
6284 }
6285
6286 bound(cur_map,0,c-1);
6287 if(map_count>oldmapcount)
6288 {
6289 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6290 {
6291 // copy the default palette to the new maps
6292 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6293
6294 Map.setCurrMap(mc);
6295 for(int32_t ms=0; ms<MAPSCRS; ms++)
6296 Map.clearscr(ms);
6297 }
6298 Map.setCurrMap(cur_map);
6299 }
6300 else
6301 {
6302 Map.setCurrMap(cur_map);
6303 if(!layers_valid(Map.CurrScr()))
6304 fix_layers(Map.CurrScr(), false);
6305
6306 for(int32_t i=0; i<MAXDMAPS; i++)
6307 {
6308 if(DMaps[i].map>=map_count)
6309 {
6310 DMaps[i].map=map_count-1;
6311 }
6312 }
6313 }
6314
6315 return true;
6316 }
6317
6318 extern BITMAP *bmap;
6319
6320 static bool loading_file_new = false;
6321 int32_t init_quest(std::string tileset_path)
6322 {
6323 if (tileset_path.empty())
6324 tileset_path = DEFAULT_TILESET;
6325
6326 loading_file_new = true;
6327 load_quest(tileset_path.c_str());
6328 loading_file_new = false;
6329
6330 set_window_title("ZC Editor - Untitled Quest");
6331 zinit.last_map = 0;
6332 zinit.last_screen = 0;
6333
6334 if(bmap != NULL)
6335 {
6336 destroy_bitmap(bmap);
6337 bmap=NULL;
6338 }
6339
6340 return 0;
6341 }
6342
6343 void set_questpwd(std::string_view pwd, bool use_keyfile)
6344 {
6345 header.use_keyfile=use_keyfile;
6346
6347 // string_view actually has some quirks that make it less than ideal here.
6348 // It'd probably be best to replace it, but this works for now.
6349 memset(header.password, 0, 256);
6350 strcpy(header.password, pwd.data());
6351 header.dirty_password=true;
6352
6353 cvs_MD5Context ctx;
6354 cvs_MD5Init(&ctx);
6355 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6356 cvs_MD5Final(header.pwd_hash, &ctx);
6357 }
6358
6359
6360 bool is_null_pwd_hash(uint8_t *pwd_hash)
6361 {
6362 cvs_MD5Context ctx;
6363 uint8_t md5sum[16];
6364 char pwd[2]="";
6365
6366 cvs_MD5Init(&ctx);
6367 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6368 cvs_MD5Final(md5sum, &ctx);
6369
6370 return (memcmp(md5sum,pwd_hash,16)==0);
6371 }
6372
6373 static DIALOG pwd_dlg[] =
6374 {
6375 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6376 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6377 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6378 // 2 (filename)
6379 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6380 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6381 // 4 (challenge hash)
6382 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6383 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6384 // 6 (password)
6385 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6386 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6387 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6388 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6389 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6390 };
6391
6392 int32_t reverse_string(char* str)
6393 {
6394
6395 if(NULL==str)
6396 {
6397 return -1; //no string
6398 }
6399
6400 int32_t l=(int32_t)strlen(str)-1; //get the string length
6401
6402 if(1==l)
6403 {
6404 return 1;
6405 }
6406
6407 char c;
6408
6409 for(int32_t x=0; x < l; x++,l--)
6410 {
6411 c = str[x];
6412 str[x] = str[l];
6413 str[l] = c;
6414 }
6415
6416 return 0;
6417 }
6418
6419 #ifdef __GNUC__
6420 #pragma GCC diagnostic push
6421 #pragma GCC diagnostic ignored "-Wunreachable-code"
6422 #endif
6423
6424 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6425 {
6426
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6427 11 return 1;
6428
6429 #ifdef __EMSCRIPTEN__
6430 return 1;
6431 #endif
6432
6433 //Protection against compiling a release version with password protection off.
6434 static bool passguard = false;
6435
6436 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6437 #define MUST_HAVE_PASSWORD
6438 passguard = true;
6439 #endif
6440
6441 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6442 #if (defined _MSC_VER || defined _NPASS)
6443 return 1;
6444 #endif
6445 #endif
6446 if(devpwd()) return 1;
6447
6448 char hash_string[33];
6449
6450 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6451 {
6452 return 1;
6453 }
6454
6455 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6456 return true;
6457
6458 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6459 pwd_dlg[2].dp=get_filename(filename);
6460 cvs_MD5Context ctx;
6461 uint8_t md5sum[16]={0};
6462 char response[33]="";
6463 char prompt[256]="";
6464
6465 memcpy(md5sum, hdr->pwd_hash, 16);
6466
6467 for(int32_t i=0; i<300; ++i)
6468 {
6469 for(int32_t j=0; j<16; ++j)
6470 {
6471 sprintf(response+j*2, "%02x", md5sum[j]);
6472 }
6473
6474 if(i&1)
6475 {
6476 reverse_string(response);
6477 }
6478
6479 if(i==149)
6480 {
6481 strcpy(hash_string, response);
6482 }
6483
6484 cvs_MD5Init(&ctx);
6485 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6486 cvs_MD5Final(md5sum, &ctx);
6487 }
6488
6489 pwd_dlg[4].dp=hash_string;
6490
6491 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6492 {
6493 sprintf(prompt,"%s",response);
6494 }
6495
6496 pwd_dlg[6].dp=prompt;
6497
6498 large_dialog(pwd_dlg);
6499
6500 int32_t cancel = do_zqdialog(pwd_dlg,6);
6501
6502 if(cancel == 8)
6503 return 2;
6504
6505 bool ret=check_questpwd(hdr, prompt);
6506
6507 if(!ret)
6508 {
6509 ret=(strcmp(response,prompt)==0);
6510 }
6511 return ret ? 1 : 0;
6512 11 }
6513
6514 void set_rules(byte* newrules);
6515 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6516 {
6517 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6518
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6519 {
6520
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6521
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6522 "\nWould you like to apply them?"
6523 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6524 11 [&](bool ret,bool dsa)
6525 {
6526 if(ret)
6527 {
6528 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6529 }
6530 if(dsa)
6531 {
6532 zc_set_config("zquest",cfg,1);
6533 }
6534 },
6535
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6536 0,false, //timeout - none
6537 true //"Don't show this again"
6538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6539 11 }
6540 11 }
6541
6542 #ifdef __GNUC__
6543 #pragma GCC diagnostic pop
6544 #endif
6545
6546 11 int32_t load_quest(const char *filename, bool show_progress)
6547 {
6548 char buf[2048];
6549 byte skip_flags[4];
6550
6551 11 dword tileset_flags = 0;
6552
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6553 {
6554 44 skip_flags[i]=0;
6555 44 }
6556
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6557 7634 set_qr(i,0);
6558 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6559
6560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6561 {
6562 init_quest(DEFAULT_TILESET);
6563 }
6564 else
6565 {
6566 11 int32_t accessret = quest_access(filename, &header);
6567
6568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6569 {
6570 init_quest(DEFAULT_TILESET);
6571
6572 if(accessret == 0)
6573 ret=qe_pwd;
6574 else
6575 ret=qe_cancel;
6576 }
6577 else
6578 {
6579 11 Map.clear();
6580 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6581 11 Map.setCurrScr(zinit.last_screen);
6582
6583
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6584
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6585
6586 extern int32_t current_mappage;
6587 11 current_mappage = 0;
6588 11 bool found_default = false;
6589
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6590 {
6591 83 auto &pg = map_page[q];
6592
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6593 {
6594 2 current_mappage = q;
6595 2 break;
6596 }
6597
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6598 72 continue;
6599 else
6600 {
6601 9 current_mappage = q;
6602 9 found_default = true;
6603 }
6604 9 }
6605
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6606
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6607
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6608 11 saved = true;
6609
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6610
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6611
6612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6613 {
6614 destroy_bitmap(bmap);
6615 bmap=NULL;
6616 }
6617
6618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6619 {
6620 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6621 set_window_title(buf);
6622 }
6623 11 }
6624 }
6625
6626 11 Map.ClearCommandHistory();
6627
6628
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6629 {
6630 void load_size_poses();
6631 load_size_poses();
6632 }
6633
6634 11 return ret;
6635 }
6636
6637 int32_t load_tileset(const char *filename, dword tsetflags)
6638 {
6639 byte skip_flags[4];
6640
6641 for(int32_t i=0; i<4; ++i)
6642 skip_flags[i]=0;
6643 for(int32_t i=0; i<qr_MAX; i++)
6644 set_qr(i,0);
6645 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6646
6647 if(ret!=qe_OK)
6648 init_quest(DEFAULT_TILESET);
6649 else
6650 {
6651 if(tsetflags & TILESET_BUGFIX)
6652 applyRuleTemplate(ruletemplateFixCompat);
6653 if(tsetflags & TILESET_SCR_BUGFIX)
6654 applyRuleTemplate(ruletemplateFixZSCompat);
6655
6656 int32_t accessret = quest_access(filename, &header);
6657
6658 if(accessret != 1)
6659 {
6660 init_quest(DEFAULT_TILESET);
6661
6662 if(accessret == 0)
6663 ret=qe_pwd;
6664 else
6665 ret=qe_cancel;
6666 }
6667 else
6668 {
6669 Map.clear();
6670 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6671 Map.setCurrScr(zinit.last_screen);
6672 extern int32_t current_mappage;
6673 current_mappage = 0;
6674 bool found_default = false;
6675 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6676 {
6677 auto &pg = map_page[q];
6678 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6679 {
6680 current_mappage = q;
6681 break;
6682 }
6683 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6684 continue;
6685 else
6686 {
6687 current_mappage = q;
6688 found_default = true;
6689 }
6690 }
6691 refresh(rALL);
6692 refresh_pal();
6693 set_rules(quest_rules);
6694
6695 if(bmap != NULL)
6696 {
6697 destroy_bitmap(bmap);
6698 bmap=NULL;
6699 }
6700
6701 set_window_title("ZC Editor - Untitled Quest");
6702 first_save = saved = false;
6703 memset(filepath,0,255);
6704 memset(temppath,0,255);
6705 }
6706 }
6707
6708 Map.ClearCommandHistory();
6709
6710 return ret;
6711 }
6712
6713 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6714 {
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6716 new_return(1);
6717
6718
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6719 new_return(2);
6720
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6722 new_return(3);
6723
6724
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6725 new_return(4);
6726
6727
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6728 {
6729
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6730 new_return(5);
6731
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6732 new_return(6);
6733 1363650 }
6734
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6735 new_return(7);
6736
6737
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6738 new_return(8);
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6740 new_return(9);
6741
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6742 new_return(10);
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6744 new_return(11);
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6746 new_return(12);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6748 new_return(13);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6750 new_return(14);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6752 new_return(15);
6753
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6754 new_return(16);
6755
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6756 new_return(17);
6757
6758
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6759 new_return(18);
6760
6761
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6762 new_return(19);
6763
6764
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6765 new_return(20);
6766
6767
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6768 new_return(21);
6769
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6770 new_return(22);
6771
6772
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6773 new_return(23);
6774
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6775 new_return(24);
6776
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6777 new_return(25);
6778
6779
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6780 new_return(26);
6781
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6782
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6783 new_return(27);
6784
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6785 new_return(28);
6786 272730 return 0;
6787 }
6788
6789 130 bool write_midi(MIDI *m,PACKFILE *f)
6790 {
6791 int32_t c;
6792
6793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6794
6795
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6796 {
6797
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6798
6799
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6800 {
6801
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6802 return false;
6803 1264 }
6804 4160 }
6805
6806 130 return true;
6807 130 }
6808
6809 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6810 {
6811 9 dword section_id=ID_HEADER;
6812 9 dword section_version=V_HEADER;
6813 9 dword section_size=0;
6814
6815 //file header string
6816
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6817 {
6818 new_return(1);
6819 }
6820
6821 //section id
6822
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6823 {
6824 new_return(2);
6825 }
6826
6827 //section version info
6828
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6829 {
6830 new_return(3);
6831 }
6832
6833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6834 {
6835 new_return(4);
6836 }
6837
6838
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6839 {
6840 18 fake_pack_writing=(writecycle==0);
6841
6842 //section size
6843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6844 {
6845 new_return(5);
6846 }
6847
6848 18 writesize=0;
6849
6850 //finally... section data
6851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6852 {
6853 new_return(6);
6854 }
6855
6856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6857 {
6858 new_return(7);
6859 }
6860
6861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6862 {
6863 new_return(8);
6864 }
6865
6866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6867 {
6868 new_return(10);
6869 }
6870
6871
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6872 {
6873 new_return(11);
6874 }
6875
6876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6877 {
6878 new_return(12);
6879 }
6880
6881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6882 {
6883 new_return(13);
6884 }
6885
6886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6887 {
6888 new_return(14);
6889 }
6890
6891
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6892 {
6893 new_return(15);
6894 }
6895
6896
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6897 {
6898 new_return(16);
6899 }
6900
6901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6902 {
6903 new_return(17);
6904 }
6905
6906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6907 {
6908 new_return(19);
6909 }
6910
6911
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6912 //this is for map count, it seems. -Z
6913 {
6914 new_return(20);
6915 }
6916
6917 18 auto version = getVersion();
6918
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6920 {
6921 new_return(21);
6922 }
6923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6924 {
6925 new_return(22);
6926 }
6927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6928 {
6929 new_return(23);
6930 }
6931 // Fourth component is deprecated.
6932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6933 {
6934 new_return(24);
6935 }
6936
6937 // Numerous prerelease stages is deprecated.
6938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6939 {
6940 new_return(25);
6941 }
6942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6943 {
6944 new_return(26);
6945 }
6946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6947 {
6948 new_return(27);
6949 }
6950
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6951 {
6952 new_return(28);
6953 }
6954
6955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6956 {
6957 new_return(29);
6958 }
6959
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6960 {
6961 new_return(30);
6962 }
6963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6964 {
6965 new_return(31);
6966 }
6967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6968 {
6969 new_return(32);
6970 }
6971
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6972 {
6973 new_return(33);
6974 }
6975
6976 // This is no longer set to anything.
6977 const char* tempsig[256];
6978 18 memset(tempsig, 0, 256);
6979
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6980 {
6981 new_return(34);
6982 }
6983
6984 char tempcompilersig[256];
6985 18 memset(tempcompilersig, 0, 256);
6986 18 strcpy(tempcompilersig, COMPILER_NAME);
6987
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6989 {
6990 new_return(35);
6991 }
6992
6993 char tempcompilerversion[256];
6994 18 memset(tempcompilerversion, 0, 256);
6995 #ifdef _MSC_VER
6996 zc_itoa(_MSC_VER,tempcompilerversion,10);
6997 #else
6998 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6999 #endif
7000
7001
7002
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
7003 {
7004 new_return(36);
7005 }
7006
7007
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
7008 {
7009 new_return(37);
7010 }
7011
7012 // V_ZC_COMPILERSIG - a deprecated version field.
7013
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
7014 {
7015 new_return(38);
7016 }
7017 #ifdef _MSC_VER
7018 if(!p_iputl((_MSC_VER / 100),f))
7019 {
7020 new_return(39);
7021 }
7022 #else
7023
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7024 {
7025 new_return(39);
7026 }
7027 #endif
7028
7029
7030
7031 #ifdef _MSC_VER
7032 if(!p_iputl((_MSC_VER % 100),f))
7033 {
7034 new_return(41);
7035 }
7036 #else
7037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7038 {
7039 new_return(41);
7040 }
7041 #endif
7042
7043 #ifdef _MSC_VER
7044 # if _MSC_VER >= 1400
7045 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7046 {
7047 new_return(40);
7048 }
7049 # else
7050 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7051 {
7052 new_return(40);
7053 }
7054 #endif
7055 #else
7056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7057 {
7058 new_return(40);
7059 }
7060 #endif
7061
7062 #ifdef _MSC_VER
7063 if(!p_iputl((_MSC_BUILD),f))
7064 {
7065 new_return(42);
7066 }
7067 #else
7068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7069 {
7070 new_return(42);
7071 }
7072 #endif
7073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7074 {
7075 new_return(43);
7076 }
7077
7078 // Modules were removed (replaced by zinfo).
7079 char tempmodulename[1024];
7080 18 memset(tempmodulename, 0, 1024);
7081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7082 {
7083 new_return(44);
7084 }
7085
7086 char tempdate[256];
7087 18 memset(tempdate, 0, 256);
7088 18 strcpy(tempdate, __DATE__);
7089
7090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7091 {
7092 new_return(45);
7093 }
7094 char temptime[256];
7095 18 memset(temptime, 0, 256);
7096 18 strcpy(temptime, __TIME__);
7097
7098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7099 {
7100 new_return(46);
7101 }
7102
7103
7104 char temptimezone[6];
7105 18 memset(temptimezone, 0, 6);
7106 18 strcpy(temptimezone, __TIMEZONE__);
7107
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7108 {
7109 new_return(47);
7110 }
7111
7112
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7113 {
7114 new_return(48);
7115 }
7116
7117
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7118 {
7119 new_return(49);
7120 }
7121
7122
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7123 {
7124 new_return(50);
7125 }
7126
7127
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7128 {
7129 9 section_size=writesize;
7130 9 }
7131 18 }
7132
7133
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7134 {
7135 char ebuf[80];
7136 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7137 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7138 }
7139
7140 9 new_return(0);
7141 }
7142
7143 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7144 {
7145 //these are here to bypass compiler warnings about unused arguments
7146 9 Header=Header;
7147
7148 9 dword section_id=ID_RULES;
7149 9 dword section_version=V_RULES;
7150 9 dword section_size=0;
7151
7152 //section id
7153
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7154 {
7155 new_return(1);
7156 }
7157
7158 //section version info
7159
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7160 {
7161 new_return(2);
7162 }
7163
7164
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7165 {
7166 new_return(3);
7167 }
7168
7169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7170 {
7171 new_return(6);
7172 }
7173
7174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7175 {
7176 18 fake_pack_writing=(writecycle==0);
7177
7178 //section size
7179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7180 {
7181 new_return(4);
7182 }
7183
7184 18 writesize=0;
7185
7186 //finally... section data
7187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7188 {
7189 new_return(5);
7190 }
7191
7192
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7193 {
7194 9 section_size=writesize;
7195 9 }
7196 18 }
7197
7198
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7199 {
7200 char ebuf[80];
7201 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7202 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7203 }
7204
7205 9 new_return(0);
7206 }
7207
7208
7209 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7210 {
7211 //these are here to bypass compiler warnings about unused arguments
7212 9 Header=Header;
7213
7214 9 dword section_id=ID_DOORS;
7215 9 dword section_version=V_DOORS;
7216 9 dword section_size=0;
7217
7218 //section id
7219
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7220 {
7221 new_return(1);
7222 }
7223
7224 //section version info
7225
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7226 {
7227 new_return(2);
7228 }
7229
7230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7231 {
7232 new_return(3);
7233 }
7234
7235
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7236 {
7237 18 fake_pack_writing=(writecycle==0);
7238
7239 //section size
7240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7241 {
7242 new_return(4);
7243 }
7244
7245 18 writesize=0;
7246
7247 //finally... section data
7248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7249 {
7250 new_return(5);
7251 }
7252
7253
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7254 {
7255 //name
7256 char name[21];
7257 320 memset(name, 21, (char)0);
7258 320 strcpy(name, DoorComboSetNames[i].c_str());
7259
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7260 {
7261 new_return(6);
7262 }
7263
7264 //up door
7265
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7266 {
7267
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7268 {
7269
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7270 {
7271 new_return(7);
7272 }
7273 11520 }
7274 2880 }
7275
7276
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7277 {
7278
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7279 {
7280
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7281 {
7282 new_return(8);
7283 }
7284 11520 }
7285 2880 }
7286
7287 //down door
7288
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7289 {
7290
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7291 {
7292
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7293 {
7294 new_return(9);
7295 }
7296 11520 }
7297 2880 }
7298
7299
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7300 {
7301
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7302 {
7303
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7304 {
7305 new_return(10);
7306 }
7307 11520 }
7308 2880 }
7309
7310
7311 //left door
7312
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7313 {
7314
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7315 {
7316
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7317
7318 {
7319 new_return(11);
7320 }
7321 17280 }
7322 2880 }
7323
7324
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7325 {
7326
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7327 {
7328
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7329 {
7330 new_return(12);
7331 }
7332 17280 }
7333 2880 }
7334
7335 //right door
7336
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7337 {
7338
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7339 {
7340
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7341 {
7342 new_return(13);
7343 }
7344 17280 }
7345 2880 }
7346
7347
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7348 {
7349
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7350 {
7351
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7352 {
7353 new_return(14);
7354 }
7355 17280 }
7356 2880 }
7357
7358
7359 //up bomb rubble
7360
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7361 {
7362
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7363 {
7364 new_return(15);
7365 }
7366 640 }
7367
7368
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7369 {
7370
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7371 {
7372 new_return(16);
7373 }
7374 640 }
7375
7376 //down bomb rubble
7377
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7378 {
7379
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7380 {
7381 new_return(17);
7382 }
7383 640 }
7384
7385
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7386 {
7387
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7388 {
7389 new_return(18);
7390 }
7391 640 }
7392
7393 //left bomb rubble
7394
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7395 {
7396
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7397 {
7398 new_return(19);
7399 }
7400 960 }
7401
7402
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7403 {
7404
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7405 {
7406 new_return(20);
7407 }
7408 960 }
7409
7410 //right bomb rubble
7411
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7412 {
7413
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7414 {
7415 new_return(21);
7416 }
7417 960 }
7418
7419
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7420 {
7421
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7422 {
7423 new_return(22);
7424 }
7425 960 }
7426
7427 //walkthrough stuff
7428
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7429 {
7430
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7431 {
7432 new_return(23);
7433 }
7434 1280 }
7435
7436
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7437 {
7438
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7439 {
7440 new_return(24);
7441 }
7442 1280 }
7443
7444 //flags
7445
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7446 {
7447
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7448 {
7449 new_return(25);
7450 }
7451 640 }
7452 320 }
7453
7454
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7455 {
7456 9 section_size=writesize;
7457 9 }
7458 18 }
7459
7460
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7461 {
7462 char ebuf[80];
7463 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7464 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7465 }
7466
7467 9 new_return(0);
7468 }
7469
7470 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7471 {
7472 //these are here to bypass compiler warnings about unused arguments
7473 9 version=version;
7474 9 build=build;
7475
7476 9 word dmap_count=count_dmaps();
7477 9 dword section_id=ID_DMAPS;
7478 9 dword section_version=V_DMAPS;
7479 9 dword section_size=0;
7480
7481 //section id
7482
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7483 {
7484 new_return(1);
7485 }
7486
7487 //section version info
7488
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7489 {
7490 new_return(2);
7491 }
7492
7493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7494 {
7495 new_return(3);
7496 }
7497
7498
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7499 {
7500 18 fake_pack_writing=(writecycle==0);
7501
7502 //section size
7503
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7504 {
7505 new_return(4);
7506 }
7507
7508 18 writesize=0;
7509
7510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7512
7513 //finally... section data
7514
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7515 {
7516 new_return(5);
7517 }
7518
7519
7520
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7521 {
7522 9216 DMaps[i].validate_subscreens();
7523
7524
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7525 {
7526 new_return(6);
7527 }
7528
7529
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7530 {
7531 new_return(7);
7532 }
7533
7534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7535 {
7536 new_return(8);
7537 }
7538
7539
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7540 {
7541 new_return(9);
7542 }
7543
7544
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7545 {
7546 new_return(10);
7547 }
7548
7549
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7550 {
7551 new_return(11);
7552 }
7553
7554
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7555 {
7556 new_return(12);
7557 }
7558
7559
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7560 {
7561 new_return(13);
7562 }
7563
7564
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7565 {
7566
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7567 {
7568 new_return(14);
7569 }
7570 73728 }
7571
7572
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7573 {
7574 new_return(15);
7575 }
7576
7577
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7578 {
7579 new_return(16);
7580 }
7581
7582
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7583 {
7584 new_return(17);
7585 }
7586
7587
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7588 {
7589 new_return(18);
7590 }
7591
7592
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7593 {
7594 new_return(19);
7595 }
7596
7597
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7598 {
7599 new_return(20);
7600 }
7601
7602
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7603 {
7604 new_return(21);
7605 }
7606
7607
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7608 {
7609 new_return(22);
7610 }
7611
7612
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7613 {
7614 new_return(23);
7615 }
7616
7617
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7618 {
7619 new_return(24);
7620 }
7621
7622
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7623 {
7624 new_return(25);
7625 }
7626
7627
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7628 {
7629 new_return(26);
7630 }
7631
7632
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7633 {
7634 new_return(25);
7635 }
7636
7637
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7638 {
7639 new_return(26);
7640 }
7641
7642
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7643 {
7644 new_return(27);
7645 }
7646
7647 byte disabled[32];
7648 9216 memset(disabled,0,32);
7649
7650
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7651 {
7652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7653 {
7654 disabled[j/8] |= (1 << (j%8));
7655 }
7656 2359296 }
7657
7658
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7659 {
7660 new_return(28);
7661 }
7662
7663
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7664 {
7665 new_return(29);
7666 }
7667
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7668 {
7669 new_return(30);
7670 }
7671
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7672 {
7673 new_return(31);
7674 }
7675
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7676 {
7677
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7678 {
7679 new_return(32);
7680 }
7681
7682 73728 }
7683
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7684 {
7685
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7686 {
7687
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7688 {
7689 new_return(33);
7690 }
7691 4792320 }
7692 73728 }
7693
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7694 {
7695 new_return(34);
7696 }
7697
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7698 {
7699 new_return(35);
7700 }
7701
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7702 {
7703
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7704 {
7705 new_return(36);
7706 }
7707 73728 }
7708
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7709 {
7710
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7711 {
7712
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7713 {
7714 new_return(37);
7715 }
7716 4792320 }
7717 73728 }
7718
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7719 {
7720 new_return(38);
7721 }
7722
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7723 {
7724
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7725 {
7726 new_return(39);
7727 }
7728 73728 }
7729
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7730 {
7731
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7732 {
7733
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7734 {
7735 new_return(40);
7736 }
7737 4792320 }
7738 73728 }
7739
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7740 {
7741 new_return(41);
7742 }
7743
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7744 {
7745 new_return(42);
7746 }
7747
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7748 {
7749 new_return(43);
7750 }
7751
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7752 {
7753 new_return(44);
7754 }
7755
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7756 {
7757 new_return(45);
7758 }
7759
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7760 new_return(46);
7761
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7762 new_return(47);
7763
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7764 {
7765 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7766 new_return(48);
7767 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7768 new_return(49);
7769 }
7770 9216 }
7771
7772
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7773 {
7774 9 section_size=writesize;
7775 9 }
7776 18 }
7777
7778
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7779 {
7780 char ebuf[80];
7781 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7782 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7783 }
7784
7785 9 new_return(0);
7786 }
7787
7788 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7789 {
7790 //these are here to bypass compiler warnings about unused arguments
7791 9 Header=Header;
7792
7793 9 dword section_id=ID_COLORS;
7794 9 dword section_version=V_COLORS;
7795 9 dword section_size = 0;
7796
7797 //section id
7798
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7799 {
7800 new_return(1);
7801 }
7802
7803
7804 //section version info
7805
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7806 {
7807 new_return(2);
7808 }
7809
7810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7811 {
7812 new_return(3);
7813 }
7814
7815
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7816 {
7817 18 fake_pack_writing=(writecycle==0);
7818
7819 //section size
7820
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7821 {
7822 new_return(4);
7823 }
7824
7825 18 writesize=0;
7826
7827
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7828 {
7829 new_return(5);
7830 }
7831
7832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7833 {
7834 new_return(6);
7835 }
7836
7837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7838 {
7839 new_return(7);
7840 }
7841
7842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7843 {
7844 new_return(8);
7845 }
7846
7847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7848 {
7849 new_return(9);
7850 }
7851
7852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7853 {
7854 new_return(10);
7855 }
7856
7857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7858 {
7859 new_return(11);
7860 }
7861
7862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7863 {
7864 new_return(12);
7865 }
7866
7867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7868 {
7869 new_return(13);
7870 }
7871
7872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7873 {
7874 new_return(14);
7875 }
7876
7877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7878 {
7879 new_return(15);
7880 }
7881
7882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7883 {
7884 new_return(16);
7885 }
7886
7887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7888 {
7889 new_return(17);
7890 }
7891
7892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7893 {
7894 new_return(18);
7895 }
7896
7897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7898 {
7899 new_return(19);
7900 }
7901
7902
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7903 {
7904 new_return(20);
7905 }
7906
7907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7908 {
7909 new_return(21);
7910 }
7911
7912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7913 {
7914 new_return(22);
7915 }
7916
7917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7918 {
7919 new_return(23);
7920 }
7921
7922
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7923 {
7924 new_return(24);
7925 }
7926
7927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7928 {
7929 new_return(31);
7930 }
7931
7932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7933 {
7934 new_return(32);
7935 }
7936
7937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7938 {
7939 new_return(33);
7940 }
7941
7942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7943 {
7944 new_return(34);
7945 }
7946
7947
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7948 {
7949 new_return(35);
7950 }
7951
7952
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7953 {
7954 new_return(36);
7955 }
7956
7957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7958 {
7959 new_return(37);
7960 }
7961
7962
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7963 {
7964 new_return(38);
7965 }
7966
7967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7968 {
7969 new_return(39);
7970 }
7971
7972
7973
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7974 {
7975 9 section_size=writesize;
7976 9 }
7977 18 }
7978
7979
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7980 {
7981 char ebuf[80];
7982 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7983 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7984 }
7985
7986 9 new_return(0);
7987 }
7988
7989 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7990 {
7991 //these are here to bypass compiler warnings about unused arguments
7992 9 Header=Header;
7993
7994 9 dword section_id=ID_ICONS;
7995 9 dword section_version=V_ICONS;
7996 9 dword section_size = 0;
7997
7998 //section id
7999
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8000 {
8001 new_return(1);
8002 }
8003
8004 //section version info
8005
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8006 {
8007 new_return(2);
8008 }
8009
8010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8011 {
8012 new_return(3);
8013 }
8014
8015
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8016 {
8017 18 fake_pack_writing=(writecycle==0);
8018
8019 //section size
8020
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8021 {
8022 new_return(4);
8023 }
8024
8025 18 writesize=0;
8026
8027
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8028 {
8029
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8030 {
8031 new_return(5);
8032 }
8033 72 }
8034
8035
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8036 {
8037 9 section_size=writesize;
8038 9 }
8039 18 }
8040
8041
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8042 {
8043 char ebuf[80];
8044 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8045 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8046 }
8047
8048 9 new_return(0);
8049 }
8050
8051 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8052 {
8053 //these are here to bypass compiler warnings about unused arguments
8054 9 Header=Header;
8055
8056 9 dword section_id=ID_MISC;
8057 9 dword section_version=V_MISC;
8058 9 word shops=count_shops(&QMisc);
8059 9 word infos=count_infos(&QMisc);
8060 9 word warprings=count_warprings(&QMisc);
8061 9 word triforces=8;
8062 9 dword section_size = 0;
8063
8064 //section id
8065
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8066 {
8067 new_return(1);
8068 }
8069
8070
8071 //section version info
8072
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8073 {
8074 new_return(2);
8075 }
8076
8077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8078 {
8079 new_return(3);
8080 }
8081
8082
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8083 {
8084 18 fake_pack_writing=(writecycle==0);
8085
8086 //section size
8087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8088 {
8089 new_return(4);
8090 }
8091
8092 18 writesize=0;
8093
8094 //shops
8095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8096 {
8097 new_return(5);
8098 }
8099
8100
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8101 {
8102
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8103 {
8104 new_return(6);
8105 }
8106
8107
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8108 {
8109
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8110 {
8111 new_return(7);
8112 }
8113 480 }
8114
8115
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8116 {
8117
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8118 {
8119 new_return(8);
8120 }
8121 480 }
8122
8123
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8124 {
8125
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8126 {
8127 new_return(9);
8128 }
8129 480 }
8130 160 }
8131
8132 //infos
8133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8134 {
8135 new_return(10);
8136 }
8137
8138
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8139 {
8140
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8141 {
8142 new_return(11);
8143 }
8144
8145
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8146 {
8147
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8148 {
8149 new_return(12);
8150 }
8151 480 }
8152
8153
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8154 {
8155
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8156 {
8157 new_return(13);
8158 }
8159 480 }
8160 160 }
8161
8162 //warp rings
8163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8164 {
8165 new_return(14);
8166 }
8167
8168
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8169 {
8170
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8171 {
8172
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8173 {
8174 new_return(15);
8175 }
8176 1872 }
8177
8178
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8179 {
8180
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8181 {
8182 new_return(16);
8183 }
8184 1872 }
8185
8186
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8187 {
8188 new_return(17);
8189 }
8190 208 }
8191
8192 //triforce pieces
8193
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8194 {
8195
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8196 {
8197 new_return(18);
8198 }
8199 144 }
8200
8201 //end string
8202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8203 {
8204 new_return(19);
8205 }
8206
8207 //V_MISC >= 8
8208
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8209 {
8210
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8211 {
8212
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8213 {
8214 new_return(20);
8215 }
8216 480 }
8217 160 }
8218 //V_MISC >= 9
8219
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8220 {
8221
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8222 new_return(21);
8223 576 }
8224
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8225 {
8226
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8227
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8228 new_return(22);
8229 576 }
8230 //V_MISC >= 11
8231
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8232 new_return(23);
8233
8234 //V_MISC >= 12
8235
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8236 {
8237
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8238 new_return(24);
8239 4608 }
8240
8241 //V_MISC >= 13
8242
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8243 {
8244 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8245
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8246 new_return(25);
8247
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8248 {
8249
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8250 new_return(25);
8251
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8252 new_return(25);
8253 3456 }
8254
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8255 new_return(25);
8256
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8257 new_return(25);
8258 1152 }
8259
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8260 {
8261 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8262
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8263 new_return(26);
8264
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8265 {
8266
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8267 new_return(26);
8268
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8269 new_return(26);
8270
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8271 new_return(26);
8272
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8273 new_return(26);
8274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8275 new_return(26);
8276 13824 }
8277 4608 }
8278
8279 //V_MISC >= 14
8280
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8281 {
8282
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8283 new_return(27);
8284 4608 }
8285
8286
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8287 {
8288 9 section_size=writesize;
8289 9 }
8290 18 }
8291
8292
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8293 {
8294 char ebuf[80];
8295 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8296 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8297 }
8298
8299 9 new_return(0);
8300 }
8301
8302 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8303 {
8304 //these are here to bypass compiler warnings about unused arguments
8305 9 Header=Header;
8306
8307 9 dword section_id=ID_ITEMS;
8308 9 dword section_version=V_ITEMS;
8309 // dword section_size=0;
8310 9 dword section_size = 0;
8311
8312 //section id
8313
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8314 {
8315 new_return(1);
8316 }
8317
8318 //section version info
8319
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8320 {
8321 new_return(2);
8322 }
8323
8324
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8325 {
8326 new_return(3);
8327 }
8328
8329
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8330 {
8331 18 fake_pack_writing=(writecycle==0);
8332
8333 //section size
8334
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8335 {
8336 new_return(4);
8337 }
8338
8339 18 writesize=0;
8340
8341 //finally... section data
8342
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8343 {
8344 new_return(5);
8345 }
8346
8347
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8348 {
8349
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8350 {
8351 new_return(5);
8352 }
8353 4608 }
8354
8355
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8356 {
8357
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8358 {
8359 new_return(6);
8360 }
8361
8362
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8363 {
8364 new_return(7);
8365 }
8366
8367
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8368 {
8369 new_return(8);
8370 }
8371
8372
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8373 {
8374 new_return(9);
8375 }
8376
8377
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8378 {
8379 new_return(10);
8380 }
8381
8382
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8383 {
8384 new_return(11);
8385 }
8386
8387
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8388 {
8389 new_return(12);
8390 }
8391
8392
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8393 {
8394 new_return(13);
8395 }
8396
8397
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8398 {
8399 new_return(14);
8400 }
8401
8402
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8403 {
8404 new_return(14);
8405 }
8406
8407
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8408 {
8409 new_return(15);
8410 }
8411
8412
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8413 {
8414 new_return(16);
8415 }
8416
8417
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8418 {
8419 new_return(17);
8420 }
8421
8422
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8423 {
8424 new_return(18);
8425 }
8426
8427
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8428 {
8429 new_return(19);
8430 }
8431
8432
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8433 {
8434 new_return(21);
8435 }
8436
8437
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8438 {
8439 new_return(22);
8440 }
8441
8442
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8443 {
8444 new_return(23);
8445 }
8446
8447
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8448 {
8449
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8450 {
8451 new_return(24);
8452 }
8453 36864 }
8454
8455
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8456 {
8457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8458 {
8459 new_return(25);
8460 }
8461 9216 }
8462
8463
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8464 {
8465 new_return(26);
8466 }
8467
8468
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8469 {
8470 new_return(27);
8471 }
8472
8473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8474 {
8475 new_return(28);
8476 }
8477
8478
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8479 {
8480 new_return(29);
8481 }
8482
8483
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8484 {
8485 new_return(30);
8486 }
8487
8488
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8489 {
8490 new_return(31);
8491 }
8492
8493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8494 {
8495 new_return(32);
8496 }
8497
8498
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8499 {
8500 new_return(33);
8501 }
8502
8503
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8504 {
8505 new_return(34);
8506 }
8507
8508
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8509 {
8510 new_return(35);
8511 }
8512
8513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8514 {
8515 new_return(36);
8516 }
8517
8518
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8519 {
8520 new_return(37);
8521 }
8522
8523
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8524 {
8525 new_return(38);
8526 }
8527
8528
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8529 {
8530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8531 {
8532 new_return(39);
8533 }
8534 9216 }
8535
8536
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8537 {
8538 new_return(40);
8539 }
8540
8541
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8542 {
8543 new_return(41);
8544 }
8545
8546
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8547 {
8548 new_return(42);
8549 }
8550
8551
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8552 {
8553 new_return(43);
8554 }
8555
8556
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8557 {
8558 new_return(44);
8559 }
8560
8561
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8562 {
8563 new_return(45);
8564 }
8565
8566
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8567 {
8568 new_return(46);
8569 }
8570
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8572 {
8573 new_return(47);
8574 }
8575
8576
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8577 {
8578 new_return(48);
8579 }
8580
8581
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8582 {
8583 new_return(48);
8584 }
8585
8586 //New itemdata vars -Z
8587 //! version 27
8588
8589
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8590 {
8591 new_return(51);
8592 }
8593
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8594 {
8595 new_return(52);
8596 }
8597
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8598
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8599 {
8600 new_return(53);
8601 }
8602 46080 }
8603 //version 28
8604
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8605 {
8606 new_return(54);
8607 }
8608
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8609 {
8610
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8611 {
8612 new_return(56);
8613 }
8614 9216 }
8615
8616
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8617 {
8618 new_return(57);
8619 }
8620
8621
8622
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8623 {
8624 new_return(58);
8625 }
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8627 {
8628 new_return(59);
8629 }
8630
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8631 {
8632 new_return(60);
8633 }
8634
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8635 {
8636 new_return(61);
8637 }
8638
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8639 {
8640 new_return(62);
8641 }
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8643 {
8644 new_return(63);
8645 }
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8647 {
8648 new_return(64);
8649 }
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8651 {
8652 new_return(73);
8653 }
8654
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8655 {
8656
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8657 {
8658 new_return(74);
8659 }
8660 9216 }
8661
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8662 {
8663 new_return(75);
8664 }
8665
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8666 {
8667 new_return(76);
8668 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8670 {
8671 new_return(77);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8674 {
8675 new_return(81);
8676 }
8677
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8678 {
8679 new_return(82);
8680 }
8681
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8682 {
8683 new_return(83);
8684 }
8685
8686
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8687 {
8688
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8689 {
8690 new_return(84);
8691 }
8692 9216 }
8693
8694 //InitD[] labels
8695
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8696 {
8697
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8698 {
8699
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8700 {
8701 new_return(85);
8702 }
8703 2396160 }
8704
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8705 {
8706
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8707 {
8708 new_return(87);
8709 }
8710 2396160 }
8711
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8712 {
8713 new_return(88);
8714 }
8715 36864 }
8716
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8717 {
8718
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8719 {
8720 new_return(89);
8721 }
8722
8723 9216 }
8724
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8725 {
8726 new_return(90);
8727 }
8728
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8729 {
8730 new_return(91);
8731 }
8732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8733
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8734 new_return(92);
8735
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8736 new_return(95);
8737
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8738 new_return(96);
8739
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8740 new_return(97);
8741
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8742 return ret;
8743
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8744 new_return(98);
8745
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8746
8747
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8748 {
8749 9 section_size=writesize;
8750 9 }
8751 18 }
8752
8753
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8754 {
8755 char ebuf[80];
8756 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8757 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8758 }
8759
8760 9 new_return(0);
8761 9 }
8762
8763 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8764 {
8765 //these are here to bypass compiler warnings about unused arguments
8766 9 Header=Header;
8767
8768 9 dword section_id=ID_WEAPONS;
8769 9 dword section_version=V_WEAPONS;
8770 9 dword section_size = 0;
8771
8772 //section id
8773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8774 {
8775 new_return(1);
8776 }
8777
8778 //section version info
8779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8780 {
8781 new_return(2);
8782 }
8783
8784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8785 {
8786 new_return(3);
8787 }
8788
8789
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8790 {
8791 18 fake_pack_writing=(writecycle==0);
8792
8793 //section size
8794
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8795 {
8796 new_return(4);
8797 }
8798
8799 18 writesize=0;
8800
8801 //finally... section data
8802
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8803 {
8804 new_return(5);
8805 }
8806
8807
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8808 {
8809
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8810 {
8811 new_return(5);
8812 }
8813 4608 }
8814
8815
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8816 {
8817
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8818 {
8819 new_return(7);
8820 }
8821
8822
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8823 {
8824 new_return(8);
8825 }
8826
8827
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8828 {
8829 new_return(9);
8830 }
8831
8832
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8833 {
8834 new_return(10);
8835 }
8836
8837
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8838 {
8839 new_return(11);
8840 }
8841
8842
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8843 {
8844 new_return(12);
8845 }
8846
8847
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8848 {
8849 new_return(12);
8850 }
8851 4608 }
8852
8853
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8854 {
8855 9 section_size=writesize;
8856 9 }
8857 18 }
8858
8859
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8860 {
8861 char ebuf[80];
8862 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8863 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8864 }
8865
8866 9 new_return(0);
8867 }
8868
8869 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8870 {
8871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8872 return qe_invalid;
8873
8874 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8875 12784 bool is_0x80_screen = j >= 0x80;
8876
8877
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8878 return qe_invalid;
8879
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8880 4404 return qe_OK;
8881 //Calculate what needs writing
8882 8380 uint32_t scr_has_flags = 0;
8883
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8884
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8885 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8886
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8887 446 scr_has_flags |= SCRHAS_ITEM;
8888
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8889 28 scr_has_flags |= SCRHAS_TWARP;
8890
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8891 {
8892
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8893
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8894
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8895 {
8896 176 scr_has_flags |= SCRHAS_TWARP;
8897 176 break;
8898 }
8899 32706 }
8900
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8901
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8902 36 scr_has_flags |= SCRHAS_SWARP;
8903
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8904 {
8905
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8906
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8907
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8908 {
8909 4270 scr_has_flags |= SCRHAS_SWARP;
8910 4270 break;
8911 }
8912 16298 }
8913
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8914 44 scr_has_flags |= SCRHAS_WARPRET;
8915
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8916 {
8917
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8918 {
8919 784 scr_has_flags |= SCRHAS_WARPRET;
8920 784 break;
8921 }
8922 30208 }
8923
8924
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8925 scr_has_flags |= SCRHAS_LAYERS;
8926
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8927 {
8928
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8929
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8930 {
8931 966 scr_has_flags |= SCRHAS_LAYERS;
8932 966 break;
8933 }
8934 44532 }
8935
8936
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8937 10 scr_has_flags |= SCRHAS_MAZE;
8938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8939 scr_has_flags |= SCRHAS_MAZE;
8940
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8941 {
8942
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8943 {
8944 scr_has_flags |= SCRHAS_MAZE;
8945 break;
8946 }
8947 33480 }
8948
8949
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8950
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8951
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8952 2968 scr_has_flags |= SCRHAS_D_S_U;
8953
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8954 {
8955
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8956 {
8957 5212 scr_has_flags |= SCRHAS_D_S_U;
8958 5212 break;
8959 }
8960 800 }
8961
8962
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8963
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8964
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8965
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8966
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8967
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8968 8380 scr_has_flags |= SCRHAS_FLAGS;
8969
8970
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8971 58 scr_has_flags |= SCRHAS_ENEMY;
8972
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8973 {
8974
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8975 {
8976 1014 scr_has_flags |= SCRHAS_ENEMY;
8977 1014 break;
8978 }
8979 73086 }
8980
8981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8982 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8983 8380 scr_has_flags |= SCRHAS_CARRY;
8984
8985
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8986 22 scr_has_flags |= SCRHAS_SCRIPT;
8987
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8988 {
8989
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8990 {
8991 scr_has_flags |= SCRHAS_SCRIPT;
8992 break;
8993 }
8994 66864 }
8995
8996
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8997 {
8998
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8999
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9000
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9001 {
9002 3076 scr_has_flags |= SCRHAS_SECRETS;
9003 3076 break;
9004 }
9005 680916 }
9006
9007
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9008 {
9009
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9010
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9011 {
9012 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9013 5360 break;
9014 }
9015 568532 }
9016
9017
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9018
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9019
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9020 || screen.timedwarptics || screen.screen_midi != -1
9021 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9022 8380 scr_has_flags |= SCRHAS_MISC;
9023
9024
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9025 return qe_invalid;
9026
9027 //Write stuff
9028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9029 {
9030
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9031 return qe_invalid;
9032
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9033 return qe_invalid;
9034
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9035 return qe_invalid;
9036
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9037 return qe_invalid;
9038
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9039 return qe_invalid;
9040
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9041 return qe_invalid;
9042
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9043 return qe_invalid;
9044 8380 }
9045
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9046 {
9047
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9050 return qe_invalid;
9051
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9052 return qe_invalid;
9053
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9054 return qe_invalid;
9055 446 }
9056
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9057 {
9058
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9059 return qe_invalid;
9060 4374 }
9061
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9062 {
9063
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9064 {
9065
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9066 return qe_invalid;
9067 816 }
9068
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9069 {
9070
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9071 return qe_invalid;
9072 816 }
9073
9074
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9075 {
9076
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9077 return qe_invalid;
9078 816 }
9079
9080
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9081 return qe_invalid;
9082 204 }
9083
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9084 {
9085
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9086 {
9087
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9088 return qe_invalid;
9089 17224 }
9090
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9091 {
9092
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9093 return qe_invalid;
9094 17224 }
9095
9096
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9097 {
9098
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9099 return qe_invalid;
9100 17224 }
9101
9102
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9103 return qe_invalid;
9104
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9105 return qe_invalid;
9106 4306 }
9107
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9108 {
9109
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9112 return qe_invalid;
9113 3312 }
9114
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9115 {
9116
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9117 return qe_invalid;
9118 3312 }
9119
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9120 return qe_invalid;
9121
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9122 return qe_invalid;
9123 828 }
9124
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9125 {
9126
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9127 {
9128
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9129 return qe_invalid;
9130 5796 }
9131
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9132 {
9133
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9134 return qe_invalid;
9135 5796 }
9136
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9137 {
9138
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9139 return qe_invalid;
9140 5796 }
9141
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9142 return qe_invalid;
9143
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9144 return qe_invalid;
9145 966 }
9146
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9147 {
9148
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9149 {
9150
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9151 return qe_invalid;
9152 40 }
9153
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9154 return qe_invalid;
9155
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9156 return qe_invalid;
9157 10 }
9158
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9159 {
9160
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9161 return qe_invalid;
9162
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9163 {
9164
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9165 return qe_invalid;
9166 32720 }
9167
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9168 return qe_invalid;
9169
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9170 return qe_invalid;
9171
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9172 return qe_invalid;
9173
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9174 return qe_invalid;
9175 8180 }
9176
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9177 {
9178
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9185 return qe_invalid;
9186
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9187 return qe_invalid;
9188
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9189 return qe_invalid;
9190
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9193 return qe_invalid;
9194
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9195 return qe_invalid;
9196
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9197 return qe_invalid;
9198
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9199 return qe_invalid;
9200 1294 }
9201
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9202 {
9203
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9204 {
9205
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9206 return qe_invalid;
9207 10720 }
9208
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9209 return qe_invalid;
9210 1072 }
9211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9212 {
9213
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9224 return qe_invalid;
9225 8380 }
9226
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9227 {
9228
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9231 return qe_invalid;
9232
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9233 {
9234
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9235 return qe_invalid;
9236 176 }
9237 22 }
9238
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9239 {
9240
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9241 {
9242
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9243 return qe_invalid;
9244 393728 }
9245
9246
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9247 {
9248
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9249 return qe_invalid;
9250 393728 }
9251
9252
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9253 {
9254
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9255 return qe_invalid;
9256 393728 }
9257 3076 }
9258
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9259 {
9260
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9261 {
9262
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9263 return qe_invalid;
9264 943360 }
9265
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9266 {
9267
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9268 return qe_invalid;
9269 943360 }
9270
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9271 {
9272
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9273 return qe_invalid;
9274 943360 }
9275 5360 }
9276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9277 {
9278
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9279 return qe_invalid;
9280
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9281 return qe_invalid;
9282
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9285 return qe_invalid;
9286
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9287 return qe_invalid;
9288
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9289 return qe_invalid;
9290
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9291 return qe_invalid;
9292
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9293 return qe_invalid;
9294
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9295 return qe_invalid;
9296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9299 return qe_invalid;
9300 8380 }
9301
9302 8380 dword numffc = screen.numFFC();
9303
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9304 return qe_invalid;
9305
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9306 {
9307 245678 ffcdata const& tempffc = screen.ffcs[k];
9308
9309
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9310 return qe_invalid;
9311
9312
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9313 243364 continue;
9314
9315
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9316 return qe_invalid;
9317
9318
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9319 return qe_invalid;
9320
9321
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9322 return qe_invalid;
9323
9324
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9325 return qe_invalid;
9326
9327
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9328 return qe_invalid;
9329
9330
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9331 return qe_invalid;
9332
9333
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9334 return qe_invalid;
9335
9336
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9337 return qe_invalid;
9338
9339
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9340 return qe_invalid;
9341
9342
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9343 return qe_invalid;
9344
9345
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9346 return qe_invalid;
9347
9348
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9349 return qe_invalid;
9350
9351
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9352 return qe_invalid;
9353
9354
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9355 return qe_invalid;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9358 return qe_invalid;
9359
9360
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9361 {
9362
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9363 return qe_invalid;
9364 18512 }
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9367 return qe_invalid;
9368 2314 }
9369
9370
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9371 return qe_invalid;
9372
9373
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9374 {
9375
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9378 return qe_invalid;
9379 6 }
9380
9381 8380 return qe_OK;
9382 12784 }
9383
9384 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9385 {
9386 9 dword section_id=ID_MAPS;
9387 9 dword section_version=V_MAPS;
9388 9 dword section_size = 0;
9389
9390 //section id
9391
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9392 {
9393 new_return(1);
9394 }
9395
9396 //section version info
9397
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9398 {
9399 new_return(2);
9400 }
9401
9402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9403 {
9404 new_return(3);
9405 }
9406
9407
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9408 {
9409 18 fake_pack_writing=(writecycle==0);
9410
9411 //section size
9412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9413 {
9414 new_return(4);
9415 }
9416
9417 18 writesize=0;
9418
9419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9420 {
9421 new_return(5);
9422 }
9423 18 map_infos.resize(map_count);
9424
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9425 {
9426 100 byte valid = 0;
9427
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9428 {
9429
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9430 break;
9431 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9432
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9433 {
9434 94 valid = 1;
9435 94 break;
9436 }
9437 1188 }
9438
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9439 {
9440 new_return(6);
9441 }
9442
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9443
9444 { //per-map info
9445 94 auto const& mapinf = map_infos[i];
9446
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9447 {
9448
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9449 new_return(7);
9450 564 }
9451
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9452 new_return(9);
9453
9454
9455
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9456 {
9457
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9458 {
9459
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9460 {
9461 new_return(8);
9462 }
9463 6016 }
9464 752 }
9465 }
9466
9467
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9468 12784 writemapscreen(f,i,j);
9469 94 }
9470
9471
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9472 {
9473 9 section_size=writesize;
9474 9 }
9475 18 }
9476
9477
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9478 {
9479 char ebuf[80];
9480 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9481 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9482 }
9483
9484 9 new_return(0);
9485 }
9486
9487 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9488 {
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9490 return 22;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9492 return 22;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9494 return 23;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9496 return 34;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9498 return 35;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9500 return 36;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9502 return 37;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9504 return 38;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9506 return 39;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9508 return 40;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9510 return 41;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9512 return 42;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9514 return 43;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9516 return 44;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9518 return 45;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9520 return 46;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9522 return 47;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9524 return 48;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9526 return 49;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9528 return 50;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9530 return 51;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9532 return 52;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9534 return 53;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9536 return 69;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9538 return 70;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9540 return 71;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9542 return 72;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9544 return 76;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9546 return 77;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9548 return 89;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9550 return 90;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9552 return 91;
9553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9554 return 92;
9555
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9557 return 93;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9559 return 94;
9560
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9561 return 95;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9563 return 96;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9565 return 97;
9566
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9567 return 98;
9568
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9569 return 99;
9570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9571 return 100;
9572
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9573 return 101;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9575 return 102;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9577 return 103;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9579 return 104;
9580
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9581 return 105;
9582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9583 return 106;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9585 return 107;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9587 return 108;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9589 return 109;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9591 return 110;
9592
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9593 return 111;
9594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9595 return 112;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9597 return 113;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9599 return 114;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9601 return 115;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9603 return 116;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9605 return 117;
9606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9607 return 118;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9609 return 119;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9611 return 120;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9613 return 121;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9615 return 122;
9616
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9617 return 123;
9618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9619 return 124;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9621 return 125;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9623 return 126;
9624 460 return 0;
9625 460 }
9626 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9627 {
9628 //Check what needs writing
9629 258906 word combo_has_flags = 0;
9630
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9631 {
9632
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9633
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9634 {
9635 3190 combo_has_flags |= CHAS_ATTRIB;
9636 3190 break;
9637 }
9638 2052960 }
9639
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9640 460 combo_has_flags |= CHAS_TRIG;
9641
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9642 298 combo_has_flags |= CHAS_FLAG;
9643
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9644
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9645
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9646 28174 combo_has_flags |= CHAS_ANIM;
9647
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9648 6 combo_has_flags |= CHAS_SCRIPT;
9649
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9650 {
9651
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9652 {
9653 combo_has_flags |= CHAS_SCRIPT;
9654 break;
9655 }
9656 2071200 }
9657
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9658
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9659 82514 combo_has_flags |= CHAS_BASIC;
9660
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9661
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9662
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9663
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9664
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9665
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9666
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9667 10 combo_has_flags |= CHAS_LIFT;
9668
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9669
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9670
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9671
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9672
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9673
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9674 258906 combo_has_flags |= CHAS_GENERAL;
9675
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9676 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9677
9678
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9679 {
9680 return 50;
9681 }
9682
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9683 //Write the combo
9684
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9685 {
9686
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9687 return 6;
9688
9689
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9690 return 7;
9691
9692
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9693 return 8;
9694
9695
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9696 return 9;
9697
9698
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9699 return 15;
9700
9701
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9702 return 10;
9703 82514 }
9704
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9705 {
9706 6 p_putcstr(tmp_cmb.label, f);
9707
9708
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9709 return 26;
9710
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9711
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9712 return 27;
9713 6 }
9714
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9715 {
9716
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9717 return 11;
9718
9719
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9720 return 12;
9721
9722
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9723 return 13;
9724
9725
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9726 return 14;
9727
9728
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9729 return 16;
9730
9731
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9732 return 18;
9733
9734
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9735 return 19;
9736 28174 }
9737
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9738 {
9739
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9740
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9741 return 20;
9742
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9743
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9744 return 25;
9745
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9746
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9747 return 32;
9748 3190 }
9749
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9750 {
9751
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9752 return 21;
9753
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9754 return 33;
9755 298 }
9756
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9757 {
9758
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9759
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9760 return 34;
9761
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9762 {
9763 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9764
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9765 460 }
9766
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9767 return 35;
9768 460 }
9769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9770 {
9771
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9772 return 54;
9773
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9774 return 55;
9775
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9776 return 56;
9777
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9778 return 57;
9779
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9780 return 58;
9781
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9782 return 59;
9783
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9784 return 60;
9785
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9786 return 61;
9787
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9788 return 62;
9789
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9790 return 63;
9791
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9792 return 64;
9793
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9794 return 65;
9795
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9796 return 66;
9797
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9798 return 67;
9799
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9800 return 68;
9801
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9802 return 78;
9803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9804 return ret;
9805 258906 }
9806
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9807 {
9808
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9809 return 73;
9810
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9811 return 74;
9812
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9813 return 75;
9814
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9815 return 79;
9816
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9817 return 80;
9818
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9819 return 81;
9820
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9821 return 82;
9822
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9823 return 83;
9824
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9825 return 84;
9826
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9827 return 85;
9828
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9829 return 86;
9830
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9831 return 87;
9832
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9833 return 88;
9834
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9835 return 89;
9836
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9837 return 90;
9838
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9839 return 91;
9840
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9841 return 92;
9842
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9843 return 93;
9844
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9845 return 94;
9846
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9847 return 95;
9848
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9849 return 96;
9850
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9851 return 97;
9852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9853 return 98;
9854 2200 }
9855
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9856 {
9857 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9858 return ret;
9859 }
9860 258906 return 0;
9861 258906 }
9862
9863 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9864 {
9865 //these are here to bypass compiler warnings about unused arguments
9866 9 version=version;
9867 9 build=build;
9868
9869 word combos_used;
9870 9 dword section_id=ID_COMBOS;
9871 9 dword section_version=V_COMBOS;
9872 // dword section_size=0;
9873 9 combos_used = count_combos()-start_combo;
9874
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9875
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9876 9 dword section_size = 0;
9877
9878 //section id
9879
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9880 {
9881 new_return(1);
9882 }
9883
9884 //section version info
9885
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9886 {
9887 new_return(2);
9888 }
9889
9890
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9891 {
9892 new_return(3);
9893 }
9894
9895
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9896 {
9897 18 fake_pack_writing=(writecycle==0);
9898
9899 //section size
9900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9901 {
9902 new_return(4);
9903 }
9904
9905 18 writesize=0;
9906
9907 //finally... section data
9908 18 combos_used=count_combos()-start_combo;
9909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9911
9912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9913 {
9914 new_return(5);
9915 }
9916
9917 18 size_t end_combo = start_combo+combos_used;
9918
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9919 {
9920 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9921
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9922 258906 }
9923
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9924 {
9925 9 section_size=writesize;
9926 9 }
9927 18 }
9928
9929
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9930 {
9931 char ebuf[80];
9932 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9933 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9934 }
9935
9936 9 new_return(0);
9937 9 }
9938
9939 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9940 {
9941 //these are here to bypass compiler warnings about unused arguments
9942 9 version=version;
9943 9 build=build;
9944
9945 9 dword section_id=ID_COMBOALIASES;
9946 9 dword section_version=V_COMBOALIASES;
9947 9 dword section_size=0;
9948
9949 //section id
9950
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9951 {
9952 new_return(1);
9953 }
9954
9955 //section version info
9956
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9957 {
9958 new_return(2);
9959 }
9960
9961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9962 {
9963 new_return(3);
9964 }
9965
9966
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9967 {
9968 18 fake_pack_writing=(writecycle==0);
9969
9970 //section size
9971
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9972 {
9973 new_return(4);
9974 }
9975
9976 18 writesize=0;
9977
9978 //finally... section data
9979
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9980 {
9981
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9982 {
9983 new_return(5);
9984 }
9985
9986
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9987 {
9988 new_return(6);
9989 }
9990
9991 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9992
9993
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9994 {
9995 new_return(7);
9996 }
9997
9998
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9999 {
10000 new_return(8);
10001 }
10002
10003
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10004 {
10005 new_return(9);
10006 }
10007
10008
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10009 {
10010
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10011 {
10012 new_return(10);
10013 }
10014 149596 }
10015
10016
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10017 {
10018
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10019 {
10020 new_return(11);
10021 }
10022 149596 }
10023 147456 }
10024
10025 //Combo pools!
10026 int16_t num_cpools;
10027
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10028 {
10029
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10030 {
10031 2 ++num_cpools;
10032 2 break;
10033 }
10034 147450 }
10035
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10036
10037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10038 {
10039 new_return(12);
10040 }
10041
10042
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10043 {
10044 6 combo_pool const& pool = combo_pools[cp];
10045 6 int32_t num_combos = pool.combos.size();
10046
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10047 {
10048 new_return(13);
10049 }
10050
10051
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10052 {
10053 26 cpool_entry const& entry = pool.combos.at(q);
10054
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10055 {
10056 new_return(14);
10057 }
10058
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10059 {
10060 new_return(15);
10061 }
10062
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10063 {
10064 new_return(16);
10065 }
10066 26 }
10067 6 }
10068
10069 //Autocombos!
10070 int16_t num_cautos;
10071
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10072 {
10073
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10074 {
10075 ++num_cautos;
10076 break;
10077 }
10078 147456 }
10079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10080
10081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10082 {
10083 new_return(17);
10084 }
10085
10086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10087 {
10088 combo_auto const& cauto = combo_autos[ca];
10089 if (!p_putc(cauto.getType(), f))
10090 {
10091 new_return(18);
10092 }
10093 if (!p_iputl(cauto.getIconDisplay(), f))
10094 {
10095 new_return(19);
10096 }
10097 if (!p_iputl(cauto.getEraseCombo(), f))
10098 {
10099 new_return(20);
10100 }
10101 if (!p_putc(cauto.getFlags(), f))
10102 {
10103 new_return(21);
10104 }
10105 if (!p_putc(cauto.getArg(), f))
10106 {
10107 new_return(22);
10108 }
10109 int32_t num_combos = cauto.combos.size();
10110 if (!p_iputl(num_combos, f))
10111 {
10112 new_return(23);
10113 }
10114
10115 for (auto q = 0; q < num_combos; ++q)
10116 {
10117 autocombo_entry const& entry = cauto.combos.at(q);
10118 if (!p_putc(entry.ctype, f))
10119 {
10120 new_return(24);
10121 }
10122 if (!p_iputl(entry.cid, f))
10123 {
10124 new_return(25);
10125 }
10126 }
10127 }
10128
10129
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10130 {
10131 9 section_size=writesize;
10132 9 }
10133 18 }
10134
10135
10136
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10137 {
10138 char ebuf[80];
10139 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10140 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10141 }
10142
10143 9 new_return(0);
10144 }
10145
10146 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10147 {
10148 //these are here to bypass compiler warnings about unused arguments
10149 9 version=version;
10150 9 build=build;
10151 9 start_cset=start_cset;
10152 9 max_csets=max_csets;
10153
10154 9 dword section_id=ID_CSETS;
10155 9 dword section_version=V_CSETS;
10156 9 int32_t palcycles = count_palcycles(&QMisc);
10157 // int32_t palcyccount = count_palcycles(&QMisc);
10158 9 dword section_size = 0;
10159
10160 //section id
10161
10162
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10163 {
10164 new_return(1);
10165 }
10166
10167 //section version info
10168
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10169 {
10170 new_return(2);
10171 }
10172
10173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10174 {
10175 new_return(3);
10176 }
10177
10178
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10179 {
10180 18 fake_pack_writing=(writecycle==0);
10181
10182 //section size
10183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10184 {
10185 new_return(4);
10186 }
10187
10188 18 writesize=0;
10189
10190 //finally... section data
10191
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10192 {
10193 new_return(5);
10194 }
10195
10196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10197 {
10198 new_return(6);
10199 }
10200
10201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10202 {
10203 new_return(15);
10204 }
10205
10206
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10207 {
10208
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10209 {
10210
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10211 {
10212 new_return(16);
10213 }
10214 1650 }
10215
10216
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10217 {
10218
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10219 {
10220 new_return(17);
10221 }
10222 1650 }
10223
10224
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10225 {
10226
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10227 {
10228 new_return(18);
10229 }
10230 1650 }
10231 550 }
10232
10233
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10234 {
10235 9 section_size=writesize;
10236 9 }
10237 18 }
10238
10239
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10240 {
10241 char ebuf[80];
10242 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10243 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10244 }
10245
10246 9 new_return(0);
10247 }
10248
10249 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10250 {
10251 //these are here to bypass compiler warnings about unused arguments
10252 9 version=version;
10253 9 build=build;
10254 9 start_msgstr=start_msgstr;
10255 9 max_msgstrs=max_msgstrs;
10256
10257 9 dword section_id=ID_STRINGS;
10258 9 dword section_version=V_STRINGS;
10259 9 dword section_size = 0;
10260
10261 //section id
10262
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10263 {
10264 new_return(1);
10265 }
10266
10267 //section version info
10268
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10269 {
10270 new_return(2);
10271 }
10272
10273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10274 {
10275 new_return(3);
10276 }
10277
10278
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10279 {
10280 18 fake_pack_writing=(writecycle==0);
10281
10282 //section size
10283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10284 {
10285 new_return(4);
10286 }
10287
10288 18 writesize=0;
10289
10290 //finally... section data
10291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10292 {
10293 return qe_invalid;
10294 }
10295
10296
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10297 {
10298 836 int32_t sz = MsgStrings[i].s.size();
10299
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10300
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10301 {
10302 return qe_invalid;
10303 }
10304
10305 836 char const* tmpstr = MsgStrings[i].s.c_str();
10306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10307 {
10308
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10309 {
10310 return qe_invalid;
10311 }
10312 836 }
10313
10314
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10315 {
10316 return qe_invalid;
10317 }
10318
10319
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10320 {
10321 return qe_invalid;
10322 }
10323
10324
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10325 {
10326 return qe_invalid;
10327 }
10328
10329
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10330 {
10331 return qe_invalid;
10332 }
10333
10334
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10335 {
10336 return qe_invalid;
10337 }
10338
10339
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10340 {
10341 return qe_invalid;
10342 }
10343
10344
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10345 {
10346 return qe_invalid;
10347 }
10348
10349
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10350 {
10351 return qe_invalid;
10352 }
10353
10354
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10355 {
10356 return qe_invalid;
10357 }
10358
10359
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10360 {
10361 return qe_invalid;
10362 }
10363
10364
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10365 {
10366 return qe_invalid;
10367 }
10368
10369
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10370 {
10371 return qe_invalid;
10372 }
10373
10374
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10375 {
10376
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10377 {
10378 return qe_invalid;
10379 }
10380 3344 }
10381
10382
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10383 {
10384 return qe_invalid;
10385 }
10386
10387
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10388 {
10389 return qe_invalid;
10390 }
10391
10392
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10393 {
10394 return qe_invalid;
10395 }
10396
10397
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10398 {
10399 return qe_invalid;
10400 }
10401
10402
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10403 {
10404 return qe_invalid;
10405 }
10406
10407
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10408 {
10409 return qe_invalid;
10410 }
10411
10412
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10413 {
10414 return qe_invalid;
10415 }
10416
10417
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10418 {
10419 return qe_invalid;
10420 }
10421
10422
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10423 {
10424 return qe_invalid;
10425 }
10426
10427
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10428 {
10429 return qe_invalid;
10430 }
10431
10432
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10433 {
10434 return qe_invalid;
10435 }
10436 836 }
10437
10438
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10439 {
10440 9 section_size=writesize;
10441 9 }
10442 18 }
10443
10444
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10445 {
10446 char ebuf[80];
10447 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10448 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10449 }
10450
10451 9 new_return(0);
10452 9 }
10453
10454 int32_t writestrings_text(PACKFILE *f)
10455 {
10456 std::map<int32_t, int32_t> msglistcache;
10457
10458 for(int32_t index = 1; index<msg_count; index++)
10459 {
10460 for(int32_t i=1; i<msg_count; i++)
10461 {
10462 if(MsgStrings[i].listpos==index)
10463 {
10464 msglistcache[index-1]=i;
10465 break;
10466 }
10467 }
10468 }
10469
10470 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10471 {
10472 fake_pack_writing=(writecycle==0);
10473 char ebuf[32];
10474
10475 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10476
10477 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10478 {
10479 return qe_invalid;
10480 }
10481
10482 for(int32_t i=1; i<msg_count; i++)
10483 {
10484 int32_t str = msglistcache[i-1];
10485
10486 if(!str)
10487 continue;
10488
10489 if(MsgStrings[str].nextstring != 0)
10490 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10491 else
10492 sprintf(ebuf,"\n\n___%d___\n", str);
10493
10494 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10495 {
10496 return qe_invalid;
10497 }
10498
10499 std::string text = MsgStrings[str].serialize();
10500 if (!pfwrite(text.c_str(), text.size(), f))
10501 {
10502 return qe_invalid;
10503 }
10504 }
10505 }
10506
10507 new_return(0);
10508 }
10509
10510 1 int32_t writestrings_tsv(PACKFILE *f)
10511 {
10512 1 std::stringstream ss;
10513
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10533
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10534
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10535
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10536
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10538
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10539
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10540 };
10541
10542
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10543 {
10544
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10545
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10546 1 break;
10547
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10548 }
10549
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10550
10551 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10552
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10553
10554
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10555 {
10556 35 auto& msg = MsgStrings[i];
10557
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10558 {
10559
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10560
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10561
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10562 35 break;
10563
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10564
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10565
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10566 35 }
10567
10568
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10569
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10570 {
10571 return qe_invalid;
10572 }
10573
10574 1 new_return(0);
10575 1 }
10576
10577 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10578
10579 void parse_strings_tsv(std::string tsv)
10580 {
10581 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10582 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10583 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10584 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10585 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10586 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10587 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10588 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10589 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10590 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10591 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10592 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10593 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10594 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10595 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10596 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10597 { "margin", [&](auto& msg, auto& text){
10598 std::vector<std::string> strs;
10599 util::split(text, strs, ' ');
10600 if (strs.size() != 4)
10601 throw std::runtime_error("margin field must have 4 components");
10602 msg.margins[0] = std::stoi(strs[0]);
10603 msg.margins[1] = std::stoi(strs[1]);
10604 msg.margins[2] = std::stoi(strs[2]);
10605 msg.margins[3] = std::stoi(strs[3]);
10606 } },
10607 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10608 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10609 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10610 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10611 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10612 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10613 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10614 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10615 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10616 };
10617
10618 std::vector<std::string> rows;
10619 util::split(tsv, rows, '\n');
10620 if (rows.size())
10621 {
10622 std::string last = rows.back();
10623 util::trimstr(last);
10624 if (last.empty())
10625 rows.pop_back();
10626 }
10627 if (rows.size() <= 1)
10628 throw std::runtime_error("missing header row");
10629
10630 std::vector<std::string> columns;
10631 util::split(rows[0], columns, '\t');
10632 for (auto name : columns)
10633 {
10634 if (!fields.contains(name))
10635 throw std::runtime_error(fmt::format("invalid field: {}", name));
10636 }
10637
10638 int start_index = 1;
10639 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10640 start_index += 1;
10641
10642 int num_strings = rows.size() - start_index + 1;
10643 if (num_strings > MAXMSGS-1)
10644 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10645
10646 std::vector<MsgStr> msgs;
10647 msgs.reserve(num_strings);
10648 for (int i = start_index; i < rows.size(); i++)
10649 {
10650 std::vector<std::string> strs;
10651 util::split(rows[i], strs, '\t');
10652 if (strs.size() != columns.size())
10653 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10654
10655 int j = 0;
10656 auto& msg = msgs.emplace_back();
10657 for (auto& name : columns)
10658 {
10659 auto& fn = fields[name];
10660 try
10661 {
10662 fn(msg, strs[j++]);
10663 }
10664 catch (std::exception& ex)
10665 {
10666 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10667 }
10668 }
10669 }
10670
10671 init_msgstrings(0, msgs.size());
10672 for (int i = 0; i < msgs.size(); i++)
10673 MsgStrings[i + 1] = msgs[i];
10674 msg_count = msgs.size() + 1;
10675 msglistcache.clear();
10676 }
10677
10678 bool isblanktile(tiledata *buf, int32_t i);
10679 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10680 {
10681 //these are here to bypass compiler warnings about unused arguments
10682 9 version=version;
10683 9 build=build;
10684
10685 int32_t tiles_used;
10686 9 dword section_id=ID_TILES;
10687 9 dword section_version=V_TILES;
10688 9 al_trace("Counting tiles used\n");
10689 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10691
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10692 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10693 9 dword section_size = 0;
10694
10695 //section id
10696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10697 {
10698 new_return(1);
10699 }
10700
10701 //section version info
10702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10703 {
10704 new_return(2);
10705 }
10706
10707
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10708 {
10709 new_return(3);
10710 }
10711
10712
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10713 {
10714 18 fake_pack_writing=(writecycle==0);
10715
10716 //section size
10717
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10718 {
10719 new_return(4);
10720 }
10721
10722 18 writesize=0;
10723
10724 //finally... section data
10725 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10727
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10728
10729
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10730 {
10731 new_return(5);
10732 }
10733
10734
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10735 {
10736
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10737 {
10738
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10739 new_return(8);
10740 365770 }
10741 else
10742 {
10743 330614 int format = newtilebuf[start_tile+i].format;
10744
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10745 {
10746 new_return(6);
10747 }
10748
10749
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10750 {
10751 byte temp_tile[128];
10752 327742 byte *di = temp_tile;
10753 327742 byte *src = newtilebuf[start_tile+i].data;
10754
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10755 {
10756 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10757 41950976 ++di;
10758 41950976 }
10759
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10760 {
10761 new_return(7);
10762 }
10763 327742 }
10764
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10765 {
10766 new_return(7);
10767 }
10768 }
10769 696384 }
10770
10771
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10772 {
10773 9 section_size=writesize;
10774 9 }
10775 18 }
10776
10777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10778 {
10779 char ebuf[80];
10780 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10781 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10782 }
10783
10784 9 new_return(0);
10785 }
10786
10787 /* MIDI Format
10788 section_id LONG
10789 section_version WORD
10790 section_cversion WORD
10791 section_size LONG
10792 midi_flags 32 Byte ? BITFIELD[252]
10793
10794 [
10795 title 36
10796 start 4
10797 loop_start 4
10798 loop_end 4
10799 loop 2
10800 volume 2
10801 midi *
10802 ]
10803
10804 */
10805
10806 9 int32_t writemidis(PACKFILE *f)
10807 {
10808 9 dword section_id=ID_MIDIS;
10809 9 dword section_version=V_MIDIS;
10810 9 dword section_size = 0;
10811
10812 //section id
10813
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10814 {
10815 new_return(1);
10816 }
10817
10818 //section version info
10819
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10820 {
10821 new_return(2);
10822 }
10823
10824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10825 {
10826 new_return(3);
10827 }
10828
10829
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10830 {
10831 18 fake_pack_writing=(writecycle==0);
10832
10833 //section size
10834
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10835 {
10836 new_return(4);
10837 }
10838
10839 18 writesize=0;
10840
10841 //finally... section data
10842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10843 {
10844 new_return(5);
10845 }
10846
10847
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10848 {
10849
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10850 {
10851
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10852 {
10853 new_return(6);
10854 }
10855
10856
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10857 {
10858 new_return(7);
10859 }
10860
10861
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10862 {
10863 new_return(8);
10864 }
10865
10866
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10867 {
10868 new_return(9);
10869 }
10870
10871
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10872 {
10873 new_return(10);
10874 }
10875
10876
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10877 {
10878 new_return(11);
10879 }
10880
10881
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10882 {
10883 new_return(12);
10884 }
10885
10886 130 byte format = MFORMAT_MIDI;
10887
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10888 {
10889 new_return(13);
10890 }
10891
10892
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10893 130 }
10894 4536 }
10895
10896
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10897 {
10898 9 section_size=writesize;
10899 9 }
10900 18 }
10901
10902
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10903 {
10904 char ebuf[80];
10905 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10906 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10907 }
10908
10909 9 new_return(0);
10910 }
10911
10912 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10913 {
10914 9 dword section_id=ID_CHEATS;
10915 9 dword section_version=V_CHEATS;
10916 9 dword section_size = 0;
10917
10918 //section id
10919
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10920 {
10921 new_return(1);
10922 }
10923
10924 //section version info
10925
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10926 {
10927 new_return(2);
10928 }
10929
10930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10931 {
10932 new_return(3);
10933 }
10934
10935
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10936 {
10937 18 fake_pack_writing=(writecycle==0);
10938
10939 //section size
10940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10941 {
10942 new_return(4);
10943 }
10944
10945 18 writesize=0;
10946
10947 //finally... section data
10948
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10949 {
10950 new_return(5);
10951 }
10952
10953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10954 {
10955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10956 {
10957 new_return(6);
10958 }
10959
10960
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10961 {
10962 new_return(7);
10963 }
10964 18 }
10965
10966
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10967 {
10968 9 section_size=writesize;
10969 9 }
10970 18 }
10971
10972
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10973 {
10974 char ebuf[80];
10975 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10976 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10977 }
10978
10979 9 new_return(0);
10980 }
10981
10982 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10983 {
10984 //these are here to bypass compiler warnings about unused arguments
10985 9 Header=Header;
10986
10987 9 dword section_id=ID_GUYS;
10988 9 dword section_version=V_GUYS;
10989 9 dword section_size=0;
10990
10991 //section id
10992
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10993 {
10994 new_return(1);
10995 }
10996
10997 //section version info
10998
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10999 {
11000 new_return(2);
11001 }
11002
11003
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11004 {
11005 new_return(3);
11006 }
11007
11008
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11009 {
11010 18 fake_pack_writing=(writecycle==0);
11011
11012 //section size
11013
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11014 {
11015 new_return(4);
11016 }
11017
11018 18 writesize=0;
11019
11020 //finally... section data
11021
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11022 {
11023
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11024 {
11025 new_return(5);
11026 }
11027 9216 }
11028
11029
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11030 {
11031 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11032 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11033
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11034 {
11035 new_return(6);
11036 }
11037
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11038 {
11039 new_return(7);
11040 }
11041
11042
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11043 {
11044 new_return(8);
11045 }
11046
11047
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11048 {
11049 new_return(9);
11050 }
11051
11052
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11053 {
11054 new_return(10);
11055 }
11056
11057
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11058 {
11059 new_return(11);
11060 }
11061
11062
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11063 {
11064 new_return(12);
11065 }
11066
11067
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11068 {
11069 new_return(13);
11070 }
11071
11072
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11073 {
11074 new_return(14);
11075 }
11076
11077
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11078 {
11079 new_return(15);
11080 }
11081
11082
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11083 {
11084 new_return(16);
11085 }
11086
11087
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11088 {
11089 new_return(17);
11090 }
11091
11092
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11093 {
11094 new_return(18);
11095 }
11096
11097
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11098 {
11099 new_return(19);
11100 }
11101
11102
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11103 {
11104 new_return(20);
11105 }
11106
11107
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11108 {
11109 new_return(21);
11110 }
11111
11112
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11113 {
11114 new_return(22);
11115 }
11116
11117
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11118 {
11119 new_return(23);
11120 }
11121
11122
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11123 {
11124 new_return(24);
11125 }
11126
11127
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11128 {
11129 new_return(25);
11130 }
11131
11132
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11133 {
11134 new_return(26);
11135 }
11136
11137
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11138 {
11139 new_return(27);
11140 }
11141
11142
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11143 {
11144 new_return(28);
11145 }
11146
11147
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11148 {
11149 new_return(29);
11150 }
11151
11152
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11153 {
11154 new_return(30);
11155 }
11156
11157
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11158 {
11159 new_return(31);
11160 }
11161
11162
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11163 {
11164 new_return(32);
11165 }
11166
11167
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11168 {
11169 new_return(33);
11170 }
11171
11172
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11173 {
11174 new_return(34);
11175 }
11176
11177
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11178 {
11179 new_return(35);
11180 }
11181
11182
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11183 {
11184 new_return(36);
11185 }
11186
11187
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11188 {
11189 new_return(37);
11190 }
11191
11192
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11193 {
11194 new_return(38);
11195 }
11196
11197
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11198 {
11199 new_return(39);
11200 }
11201
11202
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11203 {
11204 new_return(40);
11205 }
11206
11207
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11208 {
11209 new_return(41);
11210 }
11211
11212
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11213 {
11214 new_return(42);
11215 }
11216
11217
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11218 {
11219 new_return(43);
11220 }
11221
11222
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11223 {
11224 new_return(44);
11225 }
11226
11227
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11228 {
11229 new_return(45);
11230 }
11231
11232
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11233 {
11234
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11235 {
11236 new_return(46);
11237 }
11238 175104 }
11239
11240
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11241 {
11242 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11243
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11244 //Force SFX_HIT here.
11245
11246 2048 }
11247
11248
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11249 {
11250 new_return(47);
11251 }
11252
11253
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11254 {
11255 new_return(48);
11256 }
11257
11258
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11259 {
11260 new_return(49);
11261 }
11262
11263
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11264 {
11265 new_return(50);
11266 }
11267
11268 //New 2.6 defences
11269
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11270 {
11271
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11272 {
11273 new_return(51);
11274 }
11275 202752 }
11276
11277 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11278
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11279 {
11280 new_return(52);
11281 }
11282
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11283 {
11284 new_return(53);
11285 }
11286
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11287 {
11288 new_return(54);
11289 }
11290
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11291 {
11292 new_return(55);
11293 }
11294
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11295 {
11296 new_return(56);
11297 }
11298 // These are not fixed types, but ints, so they are safe to use here.
11299
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11300 {
11301 new_return(57);
11302 }
11303
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11304 {
11305 new_return(58);
11306 }
11307
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11308 {
11309 new_return(59);
11310 }
11311
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11312 {
11313 new_return(60);
11314 }
11315
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11316 {
11317 new_return(61);
11318 }
11319
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11320 {
11321 new_return(62);
11322 }
11323
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11324 {
11325 new_return(63);
11326 }
11327
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11328 {
11329 new_return(64);
11330 }
11331
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11332 {
11333 new_return(65);
11334 }
11335
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11336 {
11337 new_return(66);
11338 }
11339
11340
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11341 {
11342
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11343 {
11344 new_return(67);
11345 }
11346 92160 }
11347
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11348 {
11349 new_return(68);
11350 }
11351 //misc 16->31
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11353 {
11354 new_return(69);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11357 {
11358 new_return(70);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11361 {
11362 new_return(71);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11365 {
11366 new_return(72);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11369 {
11370 new_return(73);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11373 {
11374 new_return(74);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11377 {
11378 new_return(75);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11381 {
11382 new_return(76);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11385 {
11386 new_return(77);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11389 {
11390 new_return(78);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11393 {
11394 new_return(79);
11395 }
11396
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11397 {
11398 new_return(80);
11399 }
11400
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11401 {
11402 new_return(81);
11403 }
11404
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11405 {
11406 new_return(82);
11407 }
11408
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11409 {
11410 new_return(83);
11411 }
11412
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11413 {
11414 new_return(84);
11415 }
11416
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11417 {
11418 new_return(85);
11419 }
11420
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11421 {
11422
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11423 {
11424 new_return(86);
11425 }
11426 294912 }
11427
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11428 {
11429
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11430 {
11431 new_return(87);
11432 }
11433 294912 }
11434
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11435 {
11436 new_return(88);
11437 }
11438
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11439 {
11440
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11441 {
11442 new_return(89);
11443 }
11444 73728 }
11445
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11446 {
11447
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11448 {
11449 new_return(90);
11450 }
11451 18432 }
11452
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11453 {
11454 new_return(91);
11455 }
11456 //somehow forgot these in the older builds -Z
11457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11458 {
11459 new_return(92);
11460 }
11461
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11462 {
11463 new_return(93);
11464 }
11465
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11466 {
11467 new_return(94);
11468 }
11469
11470 //Enemy Editor InitD[] labels
11471
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11472 {
11473
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11474 {
11475
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11476 {
11477 new_return(95);
11478 }
11479 4792320 }
11480 73728 }
11481
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11482 new_return(99);
11483
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11484 new_return(100);
11485
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11486 new_return(101);
11487
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11488 new_return(102);
11489
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11490 new_return(103);
11491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11492 return ret;
11493 9216 }
11494
11495
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11496 {
11497 9 section_size=writesize;
11498 9 }
11499 18 }
11500
11501
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11502 {
11503 char ebuf[80];
11504 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11505 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11506 }
11507
11508 9 new_return(0);
11509 9 }
11510
11511 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11512 {
11513 //these are here to bypass compiler warnings about unused arguments
11514 9 Header=Header;
11515
11516 9 dword section_id=ID_HEROSPRITES;
11517 9 dword section_version=V_HEROSPRITES;
11518 9 dword section_size=0;
11519
11520 //section id
11521
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11522 {
11523 new_return(1);
11524 }
11525
11526 //section version info
11527
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11528 {
11529 new_return(2);
11530 }
11531
11532
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11533 {
11534 new_return(3);
11535 }
11536
11537
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11538 {
11539 18 fake_pack_writing=(writecycle==0);
11540
11541 //section size
11542
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11543 {
11544 new_return(4);
11545 }
11546
11547 18 writesize=0;
11548
11549 //finally... section data
11550
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11551 {
11552
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11553 {
11554 new_return(5);
11555 }
11556
11557
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11558 {
11559 new_return(5);
11560 }
11561
11562
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11563 {
11564 new_return(5);
11565 }
11566 72 }
11567
11568
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11569 {
11570
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11571 {
11572 new_return(6);
11573 }
11574
11575
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11576 {
11577 new_return(6);
11578 }
11579
11580
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11581 {
11582 new_return(6);
11583 }
11584 72 }
11585
11586
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11587 {
11588
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11589 {
11590 new_return(7);
11591 }
11592
11593
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11594 {
11595 new_return(7);
11596 }
11597
11598
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11599 {
11600 new_return(7);
11601 }
11602 72 }
11603
11604
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11605 {
11606
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11607 {
11608 new_return(8);
11609 }
11610
11611
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11612 {
11613 new_return(8);
11614 }
11615
11616
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11617 {
11618 new_return(8);
11619 }
11620 72 }
11621
11622
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11623 {
11624
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11625 {
11626 new_return(8);
11627 }
11628
11629
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11630 {
11631 new_return(8);
11632 }
11633
11634
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11635 {
11636 new_return(8);
11637 }
11638 72 }
11639
11640
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11641 {
11642
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11643 {
11644 new_return(9);
11645 }
11646
11647
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11648 {
11649 new_return(9);
11650 }
11651
11652
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11653 {
11654 new_return(9);
11655 }
11656 72 }
11657
11658
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11659 {
11660
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11661 {
11662 new_return(10);
11663 }
11664
11665
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11666 {
11667 new_return(10);
11668 }
11669
11670
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11671 {
11672 new_return(10);
11673 }
11674 72 }
11675
11676
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11677 {
11678 new_return(11);
11679 }
11680
11681
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11682 {
11683 new_return(11);
11684 }
11685
11686
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11687 {
11688 new_return(11);
11689 }
11690
11691
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11692 {
11693
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11694 {
11695
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11696 {
11697 new_return(12);
11698 }
11699
11700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11701 {
11702 new_return(12);
11703 }
11704
11705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11706 {
11707 new_return(12);
11708 }
11709 108 }
11710 36 }
11711
11712
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11713 {
11714
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11715 {
11716 new_return(13);
11717 }
11718
11719
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11720 {
11721 new_return(13);
11722 }
11723
11724
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11725 {
11726 new_return(13);
11727 }
11728 72 }
11729
11730
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11731 {
11732
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11733 {
11734 new_return(13);
11735 }
11736
11737
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11738 {
11739 new_return(13);
11740 }
11741
11742
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11743 {
11744 new_return(13);
11745 }
11746 72 }
11747
11748
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11749 {
11750 new_return(14);
11751 }
11752
11753 //{ V_HEROSPRITES >= 7
11754
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11755 {
11756
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11757 new_return(15);
11758
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11759 new_return(15);
11760
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11761 new_return(15);
11762 72 }
11763
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11764 {
11765
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11766 new_return(15);
11767
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11768 new_return(15);
11769
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11770 new_return(15);
11771 72 }
11772
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11773 {
11774
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11775 new_return(15);
11776
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11777 new_return(15);
11778
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11779 new_return(15);
11780 72 }
11781
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11782 {
11783
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11784 new_return(15);
11785
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11786 new_return(15);
11787
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11788 new_return(15);
11789 72 }
11790
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11791 {
11792
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11793 new_return(15);
11794
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11795 new_return(15);
11796
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11797 new_return(15);
11798 72 }
11799
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11800 {
11801
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11802 new_return(15);
11803
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11804 new_return(15);
11805
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11806 new_return(15);
11807 72 }
11808
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11809 {
11810
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11811 new_return(15);
11812
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11813 new_return(15);
11814
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11815 new_return(15);
11816 72 }
11817
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11818 {
11819
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11820 new_return(15);
11821
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11822 new_return(15);
11823
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11824 new_return(15);
11825 72 }
11826
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11827 {
11828
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11829 new_return(15);
11830
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11831 new_return(15);
11832
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11833 new_return(15);
11834
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11835 new_return(15);
11836 72 }
11837
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11838 {
11839
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11840 new_return(15);
11841
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11842 new_return(15);
11843
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11844 new_return(15);
11845 72 }
11846
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11847 {
11848
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11849 new_return(15);
11850
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11851 new_return(15);
11852
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11853 new_return(15);
11854 72 }
11855
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11856 {
11857
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11858 new_return(15);
11859
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11860 new_return(15);
11861
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11862 new_return(15);
11863 72 }
11864
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11865 {
11866
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11867 new_return(15);
11868
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11869 new_return(15);
11870
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11871 new_return(15);
11872 72 }
11873
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11874 {
11875
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11876 new_return(15);
11877
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11878 new_return(15);
11879
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11880 new_return(15);
11881 72 }
11882
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11883 {
11884
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11885 new_return(15);
11886
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11887 new_return(15);
11888
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11889 new_return(15);
11890 72 }
11891
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11892 {
11893
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11894 new_return(15);
11895
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11896 new_return(15);
11897
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11898 new_return(15);
11899 72 }
11900
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11901 {
11902
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11903 new_return(15);
11904
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11905 new_return(15);
11906
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11907 new_return(15);
11908 72 }
11909
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11910 {
11911
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11912 new_return(15);
11913
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11914 new_return(15);
11915
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11916 new_return(15);
11917 72 }
11918
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11919 {
11920
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11921 new_return(15);
11922
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11923 new_return(15);
11924
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11925 new_return(15);
11926 72 }
11927
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11928 {
11929
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11930 new_return(15);
11931
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11932 new_return(15);
11933
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11934 new_return(15);
11935 72 }
11936
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11937 {
11938
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11939 new_return(15);
11940
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11941 new_return(15);
11942
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11943 new_return(15);
11944 72 }
11945
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11946 {
11947
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11948 new_return(15);
11949
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11950 new_return(15);
11951
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11952 new_return(15);
11953 72 }
11954
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11955 {
11956
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11957 new_return(15);
11958
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11959 new_return(15);
11960
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11961 new_return(15);
11962 72 }
11963
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11964 {
11965
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11966 new_return(15);
11967
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11968 new_return(15);
11969
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11970 new_return(15);
11971 54 }
11972
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11973 {
11974
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11975 new_return(16);
11976
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11977 new_return(16);
11978
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11979 new_return(16);
11980 72 }
11981
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11982 {
11983
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11984 new_return(17);
11985
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11986 new_return(17);
11987
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11988 new_return(17);
11989 72 }
11990
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11991 {
11992
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11993 new_return(17);
11994
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11995 new_return(17);
11996
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11997 new_return(17);
11998 72 }
11999
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12000 {
12001
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12002 new_return(17);
12003
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12004 new_return(17);
12005
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12006 new_return(17);
12007 72 }
12008
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12009 {
12010
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12011 new_return(18);
12012
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12013 new_return(18);
12014
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12015 new_return(18);
12016 72 }
12017
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12018 {
12019
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12020 new_return(19);
12021 72 }
12022
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12023 {
12024
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12025 new_return(20);
12026
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12027 new_return(20);
12028
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12029 new_return(20);
12030 54 }
12031
12032
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12033 {
12034 new_return(21);
12035 }
12036
12037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12038 {
12039 new_return(21);
12040 }
12041
12042
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12043 {
12044 new_return(21);
12045 }
12046
12047
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12048 {
12049
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12050 new_return(22);
12051
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12052 new_return(22);
12053
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12054 new_return(22);
12055 72 }
12056
12057
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12058 {
12059
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12060 {
12061 new_return(23);
12062 }
12063
12064
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12065 {
12066 new_return(23);
12067 }
12068
12069
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12070 {
12071 new_return(23);
12072 }
12073 72 }
12074
12075
12076
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12077 {
12078
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12079 new_return(15);
12080 2628 }
12081 //}
12082
12083
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12084 {
12085 9 section_size=writesize;
12086 9 }
12087 18 }
12088
12089 //More data will come here
12090
12091
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12092 {
12093 char ebuf[80];
12094 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12095 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12096 }
12097
12098 9 new_return(0);
12099 }
12100
12101 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12102 {
12103 9 dword section_id=ID_SUBSCREEN;
12104 9 dword section_version=V_SUBSCREEN;
12105 9 dword section_size=0;
12106
12107 //section id
12108
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12109 {
12110 new_return(1);
12111 }
12112
12113 //section version info
12114
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12115 {
12116 new_return(2);
12117 }
12118
12119
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12120 {
12121 new_return(3);
12122 }
12123
12124
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12125 {
12126 18 fake_pack_writing=(writecycle==0);
12127
12128 //section size
12129
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12130 {
12131 new_return(4);
12132 }
12133
12134 18 writesize=0;
12135
12136 18 byte sz = subscreens_active.size();
12137
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12138 new_return(5);
12139
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12140 {
12141 86 int32_t ret = subscreens_active[i].write(f);
12142 86 fake_pack_writing=(writecycle==0);
12143
12144
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12145 new_return(ret);
12146 86 }
12147
12148 18 sz = subscreens_passive.size();
12149
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12150 new_return(5);
12151
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12152 {
12153 64 int32_t ret = subscreens_passive[i].write(f);
12154 64 fake_pack_writing=(writecycle==0);
12155
12156
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12157 new_return(ret);
12158 64 }
12159
12160 18 sz = subscreens_overlay.size();
12161
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12162 new_return(5);
12163
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12164 {
12165 int32_t ret = subscreens_overlay[i].write(f);
12166 fake_pack_writing=(writecycle==0);
12167
12168 if(ret!=0)
12169 new_return(ret);
12170 }
12171
12172
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12173 {
12174 9 section_size=writesize;
12175 9 }
12176 18 }
12177
12178
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12179 {
12180 char ebuf[80];
12181 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12182 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12183 }
12184
12185 9 new_return(0);
12186 9 }
12187
12188 extern script_data *ffscripts[NUMSCRIPTFFC];
12189 extern script_data *itemscripts[NUMSCRIPTITEM];
12190 extern script_data *guyscripts[NUMSCRIPTGUYS];
12191 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12192 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12193 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12194 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12195 extern script_data *playerscripts[NUMSCRIPTHERO];
12196 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12197 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12198 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12199 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12200 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12201
12202 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12203 {
12204
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12205 3 return writeffscript_old(f, Header);
12206
12207 6 dword section_id = ID_FFSCRIPT;
12208 6 dword section_version = V_FFSCRIPT;
12209 6 dword section_size = 0;
12210 6 dword zasmmeta_version = METADATA_V;
12211 6 byte numscripts = 0;
12212 6 numscripts = numscripts; //to avoid unused variables warnings
12213
12214 //section id
12215
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12216 {
12217 new_return(1);
12218 }
12219
12220 //section version info
12221
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12222 {
12223 new_return(2);
12224 }
12225
12226
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12227 {
12228 new_return(3);
12229 }
12230
12231
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12232 {
12233 new_return(4);
12234 }
12235
12236
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12237 {
12238 12 fake_pack_writing=(writecycle==0);
12239
12240 //section size
12241
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12242 {
12243 new_return(5);
12244 }
12245
12246 12 writesize=0;
12247
12248 12 write_quest_zasm(f);
12249
12250
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12251 {
12252 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12253
12254
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12255 {
12256 new_return(ret);
12257 }
12258 6144 }
12259
12260
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12261 {
12262 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12263
12264
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12265 {
12266 new_return(ret);
12267 }
12268 3072 }
12269
12270
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12271 {
12272 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12273
12274
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12275 {
12276 new_return(ret);
12277 }
12278 3072 }
12279
12280
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12281
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12282 {
12283 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12284
12285
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12286 {
12287 new_return(ret);
12288 }
12289 3072 }
12290
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12291
12292
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12293 {
12294 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12295
12296
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12297 {
12298 new_return(ret);
12299 }
12300 3072 }
12301
12302
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12303 {
12304 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12305
12306
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12307 {
12308 new_return(ret);
12309 }
12310 96 }
12311
12312
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12313 {
12314 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12315
12316
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12317 {
12318 new_return(ret);
12319 }
12320 60 }
12321
12322
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12323 {
12324 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12325
12326
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12327 {
12328 new_return(ret);
12329 }
12330 3072 }
12331
12332
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12333 {
12334 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12335
12336
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12337 {
12338 new_return(ret);
12339 }
12340 3072 }
12341
12342
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12343 {
12344 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12345
12346
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12347 {
12348 new_return(ret);
12349 }
12350 3072 }
12351
12352
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12353 {
12354 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12355
12356
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12357 {
12358 new_return(ret);
12359 }
12360 3072 }
12361
12362
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12363 {
12364 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12365
12366
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12367 {
12368 new_return(ret);
12369 }
12370 6144 }
12371
12372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12373 {
12374 new_return(2000);
12375 }
12376
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12377 {
12378 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12379
12380
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12381 {
12382 new_return(ret);
12383 }
12384 6144 }
12385
12386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12387 {
12388 new_return(2001);
12389 }
12390
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12391 {
12392 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12393
12394
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12395 {
12396 new_return(ret);
12397 }
12398 3072 }
12399
12400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12401 {
12402 new_return(2001);
12403 }
12404
12405
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12406 {
12407 new_return(2002);
12408 }
12409
12410 12 word numffcbindings=0;
12411
12412
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12413 {
12414
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12415 {
12416 158 numffcbindings++;
12417 158 }
12418 6132 }
12419
12420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12421 {
12422 new_return(2003);
12423 }
12424
12425
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12426 {
12427
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12428 {
12429
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12430 {
12431 new_return(2004);
12432 }
12433
12434
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12435 {
12436 new_return(2005);
12437 }
12438
12439
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12440 {
12441 new_return(2006);
12442 }
12443 158 }
12444 6132 }
12445
12446 12 word numglobalbindings=0;
12447
12448
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12449 {
12450
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12451 {
12452 22 numglobalbindings++;
12453 22 }
12454 96 }
12455
12456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12457 {
12458 new_return(2007);
12459 }
12460
12461
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12462 {
12463
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12464 {
12465
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12466 {
12467 new_return(2008);
12468 }
12469
12470
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12471 {
12472 new_return(2009);
12473 }
12474
12475
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12476 {
12477 new_return(2010);
12478 }
12479 22 }
12480 96 }
12481
12482 12 word numitembindings=0;
12483
12484
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12485 {
12486
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12487 {
12488 26 numitembindings++;
12489 26 }
12490 3060 }
12491
12492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12493 {
12494 new_return(2011);
12495 }
12496
12497
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12498 {
12499
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12500 {
12501
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12502 {
12503 new_return(2012);
12504 }
12505
12506
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12507 {
12508 new_return(2013);
12509 }
12510
12511
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12512 {
12513 new_return(2014);
12514 }
12515 26 }
12516 3060 }
12517
12518 //new script types
12519 //npc scripts
12520 12 word numnpcbindings=0;
12521
12522
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12523 {
12524
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12525 {
12526 numnpcbindings++;
12527 }
12528 3060 }
12529
12530
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12531 {
12532 new_return(2015);
12533 }
12534
12535
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12536 {
12537
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12538 {
12539 if(!p_iputw(it->first,f))
12540 {
12541 new_return(2016);
12542 }
12543
12544 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12545 {
12546 new_return(2017);
12547 }
12548
12549 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12550 {
12551 new_return(2018);
12552 }
12553 }
12554 3060 }
12555
12556 //lweapon
12557
12558 12 word numlwpnbindings=0;
12559
12560
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12561 {
12562
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12563 {
12564 2 numlwpnbindings++;
12565 2 }
12566 3060 }
12567
12568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12569 {
12570 new_return(2019);
12571 }
12572
12573
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12574 {
12575
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12576 {
12577
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12578 {
12579 new_return(2020);
12580 }
12581
12582
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12583 {
12584 new_return(2021);
12585 }
12586
12587
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12588 {
12589 new_return(2022);
12590 }
12591 2 }
12592 3060 }
12593
12594 //////
12595
12596 //eweapon
12597
12598
12599 12 word numewpnbindings=0;
12600
12601
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12602 {
12603
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12604 {
12605 numewpnbindings++;
12606 }
12607 3060 }
12608
12609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12610 {
12611 new_return(2023);
12612 }
12613
12614
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12615 {
12616
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12617 {
12618 if(!p_iputw(it->first,f))
12619 {
12620 new_return(2024);
12621 }
12622
12623 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12624 {
12625 new_return(2025);
12626 }
12627
12628 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12629 {
12630 new_return(2026);
12631 }
12632 }
12633 3060 }
12634
12635 //player scripts
12636 12 word numherobindings=0;
12637
12638
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12639 {
12640
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12641 {
12642 numherobindings++;
12643 }
12644 48 }
12645
12646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12647 {
12648 new_return(2027);
12649 }
12650
12651
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12652 {
12653
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12654 {
12655 if(!p_iputw(it->first,f))
12656 {
12657 new_return(2028);
12658 }
12659
12660 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12661 {
12662 new_return(2029);
12663 }
12664
12665 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12666 {
12667 new_return(2030);
12668 }
12669 }
12670 48 }
12671
12672 //dmap scripts
12673 12 word numdmapbindings=0;
12674
12675
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12676 {
12677
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12678 {
12679 10 numdmapbindings++;
12680 10 }
12681 3060 }
12682
12683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12684 {
12685 new_return(2031);
12686 }
12687
12688
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12689 {
12690
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12691 {
12692
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12693 {
12694 new_return(2032);
12695 }
12696
12697
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12698 {
12699 new_return(2033);
12700 }
12701
12702
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12703 {
12704 new_return(2034);
12705 }
12706 10 }
12707 3060 }
12708
12709 //screen scripts
12710 12 word numscreenbindings=0;
12711
12712
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12713 {
12714
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12715 {
12716 4 numscreenbindings++;
12717 4 }
12718 3060 }
12719
12720
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12721 {
12722 new_return(2035);
12723 }
12724
12725
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12726 {
12727
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12728 {
12729
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12730 {
12731 new_return(2036);
12732 }
12733
12734
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12735 {
12736 new_return(2037);
12737 }
12738
12739
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12740 {
12741 new_return(2038);
12742 }
12743 4 }
12744 3060 }
12745 //item sprite scripts
12746 12 word numitemspritebindings=0;
12747
12748
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12749 {
12750
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12751 {
12752 numitemspritebindings++;
12753 }
12754 3060 }
12755
12756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12757 {
12758 new_return(2039);
12759 }
12760
12761
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12762 {
12763
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12764 {
12765 if(!p_iputw(it->first,f))
12766 {
12767 new_return(2040);
12768 }
12769
12770 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12771 {
12772 new_return(2041);
12773 }
12774
12775 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12776 {
12777 new_return(2042);
12778 }
12779 }
12780 3060 }
12781
12782 //combo scripts
12783 12 word numcombobindings=0;
12784
12785
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12786 {
12787
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12788 {
12789 numcombobindings++;
12790 }
12791 6132 }
12792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12793 {
12794 new_return(2043);
12795 }
12796
12797
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12798 {
12799
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12800 {
12801 if(!p_iputw(it->first,f))
12802 {
12803 new_return(2044);
12804 }
12805
12806 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12807 {
12808 new_return(2045);
12809 }
12810
12811 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12812 {
12813 new_return(2046);
12814 }
12815 }
12816 6132 }
12817 //subscreen scripts
12818 12 word numgenericbindings=0;
12819
12820
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12821 {
12822
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12823 {
12824 42 numgenericbindings++;
12825 42 }
12826 6132 }
12827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12828 {
12829 new_return(2043);
12830 }
12831
12832
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12833 {
12834
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12835 {
12836
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputw(it->first,f))
12837 {
12838 new_return(2044);
12839 }
12840
12841
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12842 {
12843 new_return(2045);
12844 }
12845
12846
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12847 {
12848 new_return(2046);
12849 }
12850 42 }
12851 6132 }
12852
12853 //generic scripts
12854 12 word numsubscreenbindings=0;
12855
12856
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12857 {
12858
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12859 {
12860 numsubscreenbindings++;
12861 }
12862 3060 }
12863
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12864 {
12865 new_return(2047);
12866 }
12867
12868
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12869 {
12870
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12871 {
12872 if(!p_iputw(it->first,f))
12873 {
12874 new_return(2048);
12875 }
12876
12877 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12878 {
12879 new_return(2049);
12880 }
12881
12882 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12883 {
12884 new_return(2050);
12885 }
12886 }
12887 3060 }
12888
12889
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12890 {
12891 6 section_size=writesize;
12892 6 }
12893 12 }
12894
12895
12896
12897
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12898 {
12899 char ebuf[80];
12900 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12901 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12902 }
12903
12904 6 new_return(0);
12905 //return 0; //this is just here to stomp the compiler from whining.
12906 //the irony is that it causes an "unreachable code" warning.
12907 9 }
12908
12909 12 int32_t write_quest_zasm(PACKFILE *f)
12910 {
12911 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12912
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12913 {
12914 if(!p_iputl(0,f))
12915 new_return(1);
12916
12917 return 0;
12918 }
12919
12920 12 auto& zasm = zasm_scripts[0]->zasm;
12921 12 size_t num_commands = zasm.size();
12922
12923
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12924 new_return(1);
12925
12926
2/2
✓ Branch 0 taken 373852 times.
✓ Branch 1 taken 12 times.
373864 for(int32_t j=0; j<num_commands; j++)
12927 {
12928 373852 auto& zas = zasm[j];
12929
12930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 373852 times.
373852 if(zas.command==0xFFFF)
12931 continue;
12932 else
12933 {
12934
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputw(zas.command,f))
12935 new_return(2);
12936
12937
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputl(zas.arg1,f))
12938 new_return(3);
12939
12940
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputl(zas.arg2,f))
12941 new_return(4);
12942
12943
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputl(zas.arg3,f))
12944 new_return(5);
12945
12946 373852 uint32_t sz = 0;
12947
2/2
✓ Branch 0 taken 372884 times.
✓ Branch 1 taken 968 times.
373852 if(zas.strptr)
12948 968 sz = zas.strptr->size();
12949
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputl(sz,f))
12950 new_return(6);
12951
2/2
✓ Branch 0 taken 372896 times.
✓ Branch 1 taken 956 times.
373852 if(sz)
12952 {
12953 956 auto& str = *zas.strptr;
12954
2/2
✓ Branch 0 taken 20252 times.
✓ Branch 1 taken 956 times.
21208 for(size_t q = 0; q < sz; ++q)
12955 {
12956
1/2
✓ Branch 0 taken 20252 times.
✗ Branch 1 not taken.
20252 if(!p_putc(str[q],f))
12957 new_return(7);
12958 20252 }
12959 956 }
12960 373852 sz = 0;
12961
2/2
✓ Branch 0 taken 373644 times.
✓ Branch 1 taken 208 times.
373852 if(zas.vecptr)
12962 208 sz = zas.vecptr->size();
12963
1/2
✓ Branch 0 taken 373852 times.
✗ Branch 1 not taken.
373852 if(!p_iputl(sz,f))
12964 new_return(8);
12965
2/2
✓ Branch 0 taken 373644 times.
✓ Branch 1 taken 208 times.
373852 if(sz) //vector found
12966 {
12967 208 auto& vec = *zas.vecptr;
12968
2/2
✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 208 times.
1510 for(size_t q = 0; q < sz; ++q)
12969 {
12970
1/2
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
1302 if(!p_iputl(vec[q],f))
12971 new_return(9);
12972 1302 }
12973 208 }
12974 }
12975 373852 }
12976 12 return 0;
12977 12 }
12978
12979 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12980 {
12981
2/2
✓ Branch 0 taken 45986 times.
✓ Branch 1 taken 250 times.
46236 if (!script->valid())
12982 {
12983
1/2
✓ Branch 0 taken 45986 times.
✗ Branch 1 not taken.
45986 if (!p_putc(0, f))
12984 new_return(-1);
12985 45986 return 0;
12986 }
12987
12988
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if (!p_putc(1, f))
12989 new_return(-1);
12990
12991 250 zasm_meta const& tmeta = script->meta;
12992
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.zasm_v,f))
12993 new_return(1);
12994
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.meta_v,f))
12995 new_return(2);
12996
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.ffscript_v,f))
12997 new_return(3);
12998
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc((int)tmeta.script_type,f))
12999 new_return(4);
13000
13001
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13002 {
13003
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.run_idens[q],f))
13004 new_return(5);
13005 2000 }
13006
13007
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13008
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.run_types[q],f))
13009 new_return(6);
13010
13011
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc(tmeta.flags,f))
13012 new_return(7);
13013
13014
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v1,f))
13015 new_return(8);
13016
13017
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v2,f))
13018 new_return(9);
13019
13020
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v3,f))
13021 new_return(10);
13022
13023
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v4,f))
13024 new_return(11);
13025
13026
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.script_name,f))
13027 new_return(12);
13028
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.author,f))
13029 new_return(13);
13030
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 250 times.
2750 for(auto q = 0; q < 10; ++q)
13031 {
13032
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putcstr(tmeta.attributes[q],f))
13033 new_return(14);
13034
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putwstr(tmeta.attributes_help[q],f))
13035 new_return(15);
13036 2500 }
13037
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13038 {
13039
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attribytes[q],f))
13040 new_return(16);
13041
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attribytes_help[q],f))
13042 new_return(17);
13043 2000 }
13044
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13045 {
13046
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attrishorts[q],f))
13047 new_return(18);
13048
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13049 new_return(19);
13050 2000 }
13051
2/2
✓ Branch 0 taken 4000 times.
✓ Branch 1 taken 250 times.
4250 for(auto q = 0; q < 16; ++q)
13052 {
13053
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putcstr(tmeta.usrflags[q],f))
13054 new_return(20);
13055
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putwstr(tmeta.usrflags_help[q],f))
13056 new_return(21);
13057 4000 }
13058
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13059 {
13060
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.initd[q],f))
13061 new_return(22);
13062
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.initd_help[q],f))
13063 new_return(23);
13064 2000 }
13065
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13066 {
13067
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.initd_type[q],f))
13068 new_return(24);
13069 2000 }
13070
13071
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputl(script->pc, f))
13072 new_return(25);
13073
13074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
250 if(!p_iputl(script->end_pc, f))
13075 new_return(26);
13076
13077 250 return 0;
13078 46236 }
13079
13080
13081 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13082 {
13083 3 dword section_id = ID_FFSCRIPT;
13084 3 dword section_version = 26;
13085 3 dword section_cversion = 1;
13086 3 dword section_size = 0;
13087 3 dword zasmmeta_version = 5;
13088 3 byte numscripts = 0;
13089 3 numscripts = numscripts; //to avoid unused variables warnings
13090
13091 //section id
13092
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13093 {
13094 new_return(1);
13095 }
13096
13097 //section version info
13098
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13099 {
13100 new_return(2);
13101 }
13102
13103
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13104 {
13105 new_return(3);
13106 }
13107
13108
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13109 {
13110 new_return(4);
13111 }
13112
13113
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13114 {
13115 6 fake_pack_writing=(writecycle==0);
13116
13117 //section size
13118
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13119 {
13120 new_return(5);
13121 }
13122
13123 6 writesize=0;
13124
13125
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13126 {
13127 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13128 3072 fake_pack_writing=(writecycle==0);
13129
13130
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13131 {
13132 new_return(ret);
13133 }
13134 3072 }
13135
13136
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13137 {
13138 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13139 1536 fake_pack_writing=(writecycle==0);
13140
13141
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13142 {
13143 new_return(ret);
13144 }
13145 1536 }
13146
13147
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13148 {
13149 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13150 1536 fake_pack_writing=(writecycle==0);
13151
13152
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13153 {
13154 new_return(ret);
13155 }
13156 1536 }
13157
13158
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13159
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13160 {
13161 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13162 1536 fake_pack_writing=(writecycle==0);
13163
13164
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13165 {
13166 new_return(ret);
13167 }
13168 1536 }
13169
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13170
13171
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13172 {
13173 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13174 1536 fake_pack_writing=(writecycle==0);
13175
13176
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13177 {
13178 new_return(ret);
13179 }
13180 1536 }
13181
13182
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13183 {
13184 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13185 48 fake_pack_writing=(writecycle==0);
13186
13187
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13188 {
13189 new_return(ret);
13190 }
13191 48 }
13192
13193
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13194 {
13195 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13196 30 fake_pack_writing=(writecycle==0);
13197
13198
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13199 {
13200 new_return(ret);
13201 }
13202 30 }
13203
13204
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13205 {
13206 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13207 1536 fake_pack_writing=(writecycle==0);
13208
13209
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13210 {
13211 new_return(ret);
13212 }
13213 1536 }
13214
13215
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13216 {
13217 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13218 1536 fake_pack_writing=(writecycle==0);
13219
13220
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13221 {
13222 new_return(ret);
13223 }
13224 1536 }
13225
13226
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13227 {
13228 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13229 1536 fake_pack_writing=(writecycle==0);
13230
13231
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13232 {
13233 new_return(ret);
13234 }
13235 1536 }
13236
13237
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13238 {
13239 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13240 1536 fake_pack_writing=(writecycle==0);
13241
13242
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13243 {
13244 new_return(ret);
13245 }
13246 1536 }
13247
13248
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13249 {
13250 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13251 3072 fake_pack_writing=(writecycle==0);
13252
13253
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13254 {
13255 new_return(ret);
13256 }
13257 3072 }
13258
13259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13260 {
13261 new_return(2000);
13262 }
13263
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13264 {
13265 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13266 3072 fake_pack_writing=(writecycle==0);
13267
13268
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13269 {
13270 new_return(ret);
13271 }
13272 3072 }
13273
13274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13275 {
13276 new_return(2001);
13277 }
13278
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13279 {
13280 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13281 1536 fake_pack_writing=(writecycle==0);
13282
13283
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13284 {
13285 new_return(ret);
13286 }
13287 1536 }
13288
13289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13290 {
13291 new_return(2001);
13292 }
13293
13294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13295 {
13296 new_return(2002);
13297 }
13298
13299 6 word numffcbindings=0;
13300
13301
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13302 {
13303
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13304 {
13305 206 numffcbindings++;
13306 206 }
13307 3066 }
13308
13309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13310 {
13311 new_return(2003);
13312 }
13313
13314
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13315 {
13316
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13317 {
13318
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13319 {
13320 new_return(2004);
13321 }
13322
13323
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13324 {
13325 new_return(2005);
13326 }
13327
13328
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13329 {
13330 new_return(2006);
13331 }
13332 206 }
13333 3066 }
13334
13335 6 word numglobalbindings=0;
13336
13337
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13338 {
13339
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13340 {
13341 18 numglobalbindings++;
13342 18 }
13343 48 }
13344
13345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13346 {
13347 new_return(2007);
13348 }
13349
13350
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13351 {
13352
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13353 {
13354
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13355 {
13356 new_return(2008);
13357 }
13358
13359
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13360 {
13361 new_return(2009);
13362 }
13363
13364
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13365 {
13366 new_return(2010);
13367 }
13368 18 }
13369 48 }
13370
13371 6 word numitembindings=0;
13372
13373
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13374 {
13375
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13376 {
13377 18 numitembindings++;
13378 18 }
13379 1530 }
13380
13381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13382 {
13383 new_return(2011);
13384 }
13385
13386
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13387 {
13388
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13389 {
13390
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13391 {
13392 new_return(2012);
13393 }
13394
13395
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13396 {
13397 new_return(2013);
13398 }
13399
13400
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13401 {
13402 new_return(2014);
13403 }
13404 18 }
13405 1530 }
13406
13407 //new script types
13408 //npc scripts
13409 6 word numnpcbindings=0;
13410
13411
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13412 {
13413
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13414 {
13415 numnpcbindings++;
13416 }
13417 1530 }
13418
13419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13420 {
13421 new_return(2015);
13422 }
13423
13424
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13425 {
13426
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13427 {
13428 if(!p_iputw(it->first,f))
13429 {
13430 new_return(2016);
13431 }
13432
13433 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13434 {
13435 new_return(2017);
13436 }
13437
13438 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13439 {
13440 new_return(2018);
13441 }
13442 }
13443 1530 }
13444
13445 //lweapon
13446
13447 6 word numlwpnbindings=0;
13448
13449
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13450 {
13451
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13452 {
13453 numlwpnbindings++;
13454 }
13455 1530 }
13456
13457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13458 {
13459 new_return(2019);
13460 }
13461
13462
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13463 {
13464
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13465 {
13466 if(!p_iputw(it->first,f))
13467 {
13468 new_return(2020);
13469 }
13470
13471 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13472 {
13473 new_return(2021);
13474 }
13475
13476 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13477 {
13478 new_return(2022);
13479 }
13480 }
13481 1530 }
13482
13483 //////
13484
13485 //eweapon
13486
13487
13488 6 word numewpnbindings=0;
13489
13490
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13491 {
13492
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13493 {
13494 numewpnbindings++;
13495 }
13496 1530 }
13497
13498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13499 {
13500 new_return(2023);
13501 }
13502
13503
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13504 {
13505
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13506 {
13507 if(!p_iputw(it->first,f))
13508 {
13509 new_return(2024);
13510 }
13511
13512 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13513 {
13514 new_return(2025);
13515 }
13516
13517 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13518 {
13519 new_return(2026);
13520 }
13521 }
13522 1530 }
13523
13524 //player scripts
13525 6 word numherobindings=0;
13526
13527
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13528 {
13529
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13530 {
13531 2 numherobindings++;
13532 2 }
13533 24 }
13534
13535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13536 {
13537 new_return(2027);
13538 }
13539
13540
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13541 {
13542
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13543 {
13544
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13545 {
13546 new_return(2028);
13547 }
13548
13549
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13550 {
13551 new_return(2029);
13552 }
13553
13554
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13555 {
13556 new_return(2030);
13557 }
13558 2 }
13559 24 }
13560
13561 //dmap scripts
13562 6 word numdmapbindings=0;
13563
13564
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13565 {
13566
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13567 {
13568 numdmapbindings++;
13569 }
13570 1530 }
13571
13572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13573 {
13574 new_return(2031);
13575 }
13576
13577
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13578 {
13579
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13580 {
13581 if(!p_iputw(it->first,f))
13582 {
13583 new_return(2032);
13584 }
13585
13586 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13587 {
13588 new_return(2033);
13589 }
13590
13591 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13592 {
13593 new_return(2034);
13594 }
13595 }
13596 1530 }
13597
13598 //screen scripts
13599 6 word numscreenbindings=0;
13600
13601
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13602 {
13603
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13604 {
13605 14 numscreenbindings++;
13606 14 }
13607 1530 }
13608
13609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13610 {
13611 new_return(2035);
13612 }
13613
13614
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13615 {
13616
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13617 {
13618
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13619 {
13620 new_return(2036);
13621 }
13622
13623
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13624 {
13625 new_return(2037);
13626 }
13627
13628
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13629 {
13630 new_return(2038);
13631 }
13632 14 }
13633 1530 }
13634 //item sprite scripts
13635 6 word numitemspritebindings=0;
13636
13637
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13638 {
13639
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13640 {
13641 numitemspritebindings++;
13642 }
13643 1530 }
13644
13645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13646 {
13647 new_return(2039);
13648 }
13649
13650
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13651 {
13652
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13653 {
13654 if(!p_iputw(it->first,f))
13655 {
13656 new_return(2040);
13657 }
13658
13659 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13660 {
13661 new_return(2041);
13662 }
13663
13664 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13665 {
13666 new_return(2042);
13667 }
13668 }
13669 1530 }
13670
13671 //combo scripts
13672 6 word numcombobindings=0;
13673
13674
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13675 {
13676
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13677 {
13678 numcombobindings++;
13679 }
13680 3066 }
13681
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13682 {
13683 new_return(2043);
13684 }
13685
13686
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13687 {
13688
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13689 {
13690 if(!p_iputw(it->first,f))
13691 {
13692 new_return(2044);
13693 }
13694
13695 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13696 {
13697 new_return(2045);
13698 }
13699
13700 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13701 {
13702 new_return(2046);
13703 }
13704 }
13705 3066 }
13706 //subscreen scripts
13707 6 word numgenericbindings=0;
13708
13709
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13710 {
13711
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13712 {
13713 numgenericbindings++;
13714 }
13715 3066 }
13716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13717 {
13718 new_return(2043);
13719 }
13720
13721
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13722 {
13723
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13724 {
13725 if(!p_iputw(it->first,f))
13726 {
13727 new_return(2044);
13728 }
13729
13730 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13731 {
13732 new_return(2045);
13733 }
13734
13735 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13736 {
13737 new_return(2046);
13738 }
13739 }
13740 3066 }
13741
13742 //generic scripts
13743 6 word numsubscreenbindings=0;
13744
13745
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13746 {
13747
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13748 {
13749 numsubscreenbindings++;
13750 }
13751 1530 }
13752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13753 {
13754 new_return(2047);
13755 }
13756
13757
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13758 {
13759
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13760 {
13761 if(!p_iputw(it->first,f))
13762 {
13763 new_return(2048);
13764 }
13765
13766 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13767 {
13768 new_return(2049);
13769 }
13770
13771 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13772 {
13773 new_return(2050);
13774 }
13775 }
13776 1530 }
13777
13778
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13779 {
13780 3 section_size=writesize;
13781 3 }
13782 6 }
13783
13784
13785
13786
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13787 {
13788 char ebuf[80];
13789 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13790 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13791 }
13792
13793 3 new_return(0);
13794 //return 0; //this is just here to stomp the compiler from whining.
13795 //the irony is that it causes an "unreachable code" warning.
13796 3 }
13797
13798 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13799 {
13800 //these are here to bypass compiler warnings about unused arguments
13801 23118 Header=Header;
13802 23118 i=i;
13803
13804
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13805
13806
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13807 {
13808 new_return(6);
13809 }
13810
13811 //Metadata
13812 23118 zasm_meta const& tmeta = script->meta;
13813
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13814 {
13815 new_return(7);
13816 }
13817
13818
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13819 {
13820 new_return(8);
13821 }
13822
13823
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13824 {
13825 new_return(9);
13826 }
13827
13828
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13829 {
13830 new_return(10);
13831 }
13832
13833
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13834 {
13835
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13836 new_return(11);
13837 184944 }
13838
13839
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13840 {
13841
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13842 {
13843 new_return(12);
13844 }
13845 184944 }
13846
13847
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13848 {
13849 new_return(13);
13850 }
13851
13852
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13853 {
13854 new_return(14);
13855 }
13856
13857
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13858 {
13859 new_return(15);
13860 }
13861
13862
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13863 {
13864 new_return(16);
13865 }
13866
13867
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13868 {
13869 new_return(17);
13870 }
13871
13872
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13873 new_return(18);
13874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13875 new_return(19);
13876
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13877 {
13878
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13879 new_return(27);
13880
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13881 new_return(28);
13882 231180 }
13883
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13884 {
13885
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13886 new_return(29);
13887
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13888 new_return(30);
13889 184944 }
13890
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13891 {
13892
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13893 new_return(31);
13894
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13895 new_return(32);
13896 184944 }
13897
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13898 {
13899
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13900 new_return(33);
13901
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13902 new_return(34);
13903 369888 }
13904
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13905 {
13906
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13907 new_return(35);
13908
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13909 new_return(36);
13910 184944 }
13911
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13912 {
13913
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13914 new_return(37);
13915 184944 }
13916
13917
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13918 {
13919 2056888 auto& zas = script->zasm_script->zasm[j];
13920
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13921 {
13922 new_return(20);
13923 }
13924
13925
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13926 {
13927 11830 break;
13928 }
13929 else
13930 {
13931
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13932 {
13933 new_return(21);
13934 }
13935
13936
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13937 {
13938 new_return(22);
13939 }
13940
13941
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13942 {
13943 new_return(23);
13944 }
13945
13946 2045058 uint32_t sz = 0;
13947
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13948 2340 sz = zas.strptr->size();
13949
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13950 {
13951 new_return(23);
13952 }
13953
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13954 {
13955 2340 auto& str = *zas.strptr;
13956
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13957 {
13958
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13959 {
13960 new_return(24);
13961 }
13962 214720 }
13963 2340 }
13964 2045058 sz = 0;
13965
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13966 22 sz = zas.vecptr->size();
13967
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13968 {
13969 new_return(25);
13970 }
13971
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13972 {
13973 22 auto& vec = *zas.vecptr;
13974
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13975 {
13976
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13977 {
13978 new_return(26);
13979 }
13980 352 }
13981 22 }
13982 }
13983 2045058 }
13984
13985 23118 new_return(0);
13986 }
13987
13988 extern SAMPLE customsfxdata[WAV_COUNT];
13989 extern uint8_t customsfxflag[WAV_COUNT>>3];
13990
13991 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13992 {
13993 //these are here to bypass compiler warnings about unused arguments
13994 9 Header=Header;
13995
13996 9 dword section_id=ID_SFX;
13997 9 dword section_version=V_SFX;
13998 9 dword section_size=0;
13999
14000 //section id
14001
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14002 {
14003 new_return(1);
14004 }
14005
14006 //section version info
14007
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14008 {
14009 new_return(2);
14010 }
14011
14012
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14013 {
14014 new_return(3);
14015 }
14016
14017
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14018 {
14019 18 fake_pack_writing=(writecycle==0);
14020
14021 //section size
14022
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14023 {
14024 new_return(4);
14025 }
14026
14027 18 writesize=0;
14028
14029
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14030 {
14031
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14032 {
14033 new_return(5);
14034 }
14035 576 }
14036
14037
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14038 {
14039
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14040 3330 continue;
14041
14042
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14043 {
14044 new_return(5);
14045 }
14046 1260 }
14047
14048
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14049 {
14050
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14051 3330 continue;
14052
14053
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14054 {
14055 new_return(5);
14056 }
14057
14058
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14059 {
14060 new_return(6);
14061 }
14062
14063
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14064 {
14065 new_return(7);
14066 }
14067
14068
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14069 {
14070 new_return(8);
14071 }
14072
14073
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14074 {
14075 new_return(9);
14076 }
14077
14078
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14079 {
14080 new_return(10);
14081 }
14082
14083
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14084 {
14085 new_return(11);
14086 }
14087
14088
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14089 {
14090 new_return(12);
14091 }
14092
14093 //de-endianfy the data
14094 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14095
14096
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14097 {
14098
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14099 {
14100 new_return(13);
14101 }
14102 28596352 }
14103 1260 }
14104
14105
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14106 {
14107 9 section_size=writesize;
14108 9 }
14109 18 }
14110
14111
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14112 {
14113 char ebuf[80];
14114 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14115 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14116 }
14117
14118 9 new_return(0);
14119 }
14120
14121 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14122 {
14123 9 dword section_id=ID_INITDATA;
14124 9 dword section_version=V_INITDATA;
14125 9 dword section_size = 0;
14126
14127 9 zinit.last_map=Map.getCurrMap();
14128 9 zinit.last_screen=Map.getCurrScr();
14129 9 zinit.normalize();
14130
14131 //section id
14132
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14133 {
14134 new_return(1);
14135 }
14136
14137 //section version info
14138
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14139 {
14140 new_return(2);
14141 }
14142
14143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14144 {
14145 new_return(3);
14146 }
14147
14148 //TODO
14149
14150
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14151 {
14152 18 fake_pack_writing=(writecycle==0);
14153
14154 //section size
14155
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14156 new_return(4);
14157
14158 18 writesize=0;
14159
14160
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14161
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14162 new_return(5);
14163
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14164 {
14165
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14166 new_return(6);
14167 9216 }
14168
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14169 new_return(10);
14170
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14171 new_return(11);
14172
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14173
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14174 new_return(12);
14175
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14176
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14177 new_return(13);
14178
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14179 new_return(14);
14180
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14181 new_return(15);
14182
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14183 new_return(16);
14184
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14185 new_return(17);
14186
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14187 new_return(18);
14188
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14189 new_return(19);
14190
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14191 new_return(20);
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14193 new_return(21);
14194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14195 new_return(22);
14196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14197 new_return(23);
14198
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14199 new_return(24);
14200
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14201 new_return(25);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14203 new_return(26);
14204
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14205 new_return(27);
14206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14207 new_return(28);
14208
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14209 new_return(29);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14211 new_return(30);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14213 new_return(31);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14215 new_return(32);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14217 new_return(33);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14219 new_return(34);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14221 new_return(35);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14223 new_return(36);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14225 new_return(37);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14227 new_return(38);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14229 new_return(39);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14231 new_return(40);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14233 new_return(41);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14235 new_return(42);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14237 new_return(43);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14239 new_return(44);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14241 new_return(45);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14243 new_return(46);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14245 new_return(47);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14247 new_return(48);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14249 new_return(49);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14251 new_return(50);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14253 new_return(51);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14255 new_return(52);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14257 new_return(53);
14258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14259 new_return(54);
14260
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14261 new_return(55);
14262
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14263 new_return(56);
14264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14265 new_return(57);
14266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14267 new_return(58);
14268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14269 new_return(59);
14270
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14271 new_return(60);
14272
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14273 new_return(61);
14274
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14275 new_return(62);
14276
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14277 new_return(63);
14278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14279 new_return(64);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14281 new_return(65);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14283 new_return(66);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14285 new_return(67);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14287 new_return(68);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14289 new_return(69);
14290
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14291 new_return(70);
14292
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14293 new_return(71);
14294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14295 new_return(72);
14296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14297 new_return(73);
14298
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14299 new_return(74);
14300
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14301 new_return(75);
14302
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14303
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14304 new_return(76);
14305
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14306 new_return(77);
14307
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14308 new_return(78);
14309
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14310 new_return(79);
14311
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14312 new_return(80);
14313
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14314 new_return(81);
14315
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14316
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14317 new_return(82);
14318
14319
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14320 {
14321 9 section_size=writesize;
14322 9 }
14323 18 }
14324
14325
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14326 {
14327 char ebuf[80];
14328 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14329 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14330 }
14331
14332 9 new_return(0);
14333 }
14334
14335 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14336 {
14337 //these are here to bypass compiler warnings about unused arguments
14338 9 Header=Header;
14339
14340 9 dword section_id=ID_ITEMDROPSETS;
14341 9 dword section_version=V_ITEMDROPSETS;
14342 // dword section_size=0;
14343 9 dword section_size = 0;
14344 9 word num_item_drop_sets=count_item_drop_sets();
14345
14346 //section id
14347
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14348 {
14349 new_return(1);
14350 }
14351
14352 //section version info
14353
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14354 {
14355 new_return(2);
14356 }
14357
14358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14359 {
14360 new_return(3);
14361 }
14362
14363
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14364 {
14365 18 fake_pack_writing=(writecycle==0);
14366
14367 //section size
14368
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14369 {
14370 new_return(4);
14371 }
14372
14373 18 writesize=0;
14374
14375 //finally... section data
14376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14377 {
14378 new_return(5);
14379 }
14380
14381
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14382 {
14383
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14384 {
14385 new_return(6);
14386 }
14387
14388
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14389 {
14390
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14391 {
14392 new_return(7);
14393 }
14394 2360 }
14395
14396
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14397 {
14398
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14399 {
14400 new_return(8);
14401 }
14402 2596 }
14403 236 }
14404
14405
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14406 {
14407 9 section_size=writesize;
14408 9 }
14409 18 }
14410
14411
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14412 {
14413 char ebuf[80];
14414 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14415 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14416 }
14417
14418 9 new_return(0);
14419 }
14420
14421 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14422 {
14423 9 dword section_id=ID_FAVORITES;
14424 9 dword section_version=V_FAVORITES;
14425 9 dword section_size = 0;
14426
14427 //section id
14428
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14429 {
14430 new_return(1);
14431 }
14432
14433 //section version info
14434
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14435 {
14436 new_return(2);
14437 }
14438
14439
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14440 {
14441 new_return(3);
14442 }
14443
14444
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14445 {
14446 18 fake_pack_writing=(writecycle==0);
14447
14448 //section size
14449
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14450 new_return(4);
14451
14452 18 writesize=0;
14453
14454
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14455 new_return(16);
14456
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14457 new_return(17);
14458
14459 18 word favcmb_cnt = 0;
14460
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14461
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14462 {
14463 14 favcmb_cnt = q+1;
14464 14 break;
14465 }
14466
14467
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14468 new_return(5);
14469
14470
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14471 {
14472
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14473 new_return(6);
14474
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14475 new_return(7);
14476 460 }
14477
14478
14479 18 word max_combo_cols = MAX_COMBO_COLS;
14480
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14481 new_return(9);
14482
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14483 {
14484
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14485 new_return(10);
14486
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14487 new_return(11);
14488
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14489 new_return(12);
14490 72 }
14491 18 word max_mappages = MAX_MAPPAGE_BTNS;
14492
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14493 new_return(13);
14494
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14495 {
14496
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14497 new_return(14);
14498
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14499 new_return(15);
14500 162 }
14501
14502
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14503 {
14504 9 section_size=writesize;
14505 9 }
14506 18 }
14507
14508
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14509 {
14510 char ebuf[80];
14511 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14512 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14513 }
14514
14515 9 new_return(0);
14516 }
14517
14518 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14519 {
14520
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14521 9 reset_combo_animations();
14522 9 reset_combo_animations2();
14523 9 strcpy(header.id_str,QH_NEWIDSTR);
14524 9 header.zelda_version = ZELDA_VERSION;
14525 9 header.internal = INTERNAL_VERSION;
14526 9 header.data_flags[ZQ_TILES] = true;
14527 9 header.data_flags[ZQ_CHEATS2] = 1;
14528 9 header.build=VERSION_BUILD;
14529
14530
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14531 {
14532 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14533 2268 }
14534
14535 char zinfofilename[2048];
14536 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14537
14538 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14539 9 box_out("Saving Quest...");
14540 9 box_eol();
14541 9 box_eol();
14542
14543
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14544
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14545
14546
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14547 return 1;
14548
14549
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14550
14551
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14552 return 2;
14553
14554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14555
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14556
14557
14558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14559 {
14560 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14561
14562 box_out("Writing ZInfo...");
14563 if(inf)
14564 {
14565 if(writezinfo(inf,ZI)!=0)
14566 return 2;
14567
14568 pack_fclose(inf);
14569 box_out("okay.");
14570 }
14571 else box_out(" ...file failure");
14572 box_eol();
14573 }
14574 else
14575 {
14576
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14577
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14578 return 2;
14579
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14580
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14581 }
14582
14583
14584
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14585
14586
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14587 return 3;
14588
14589
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14590
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14591
14592
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14593
14594
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14595 return 4;
14596
14597
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14599
14600
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14601
14602
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14603 return 5;
14604
14605
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14606
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14607
14608
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14609
14610
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14611 return 6;
14612
14613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14615
14616
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14617
14618
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14619 return 7;
14620
14621
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14622
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14623
14624
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14625
14626
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14627 return 8;
14628
14629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14630
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14631
14632
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14633
14634
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14635 return 9;
14636
14637
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14638
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14639
14640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14641
14642
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14643 return 10;
14644
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14647
14648
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14649
14650
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14651 return 11;
14652
14653
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14655
14656
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14657
14658
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14659 return 12;
14660
14661
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14663
14664
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14665
14666
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14667 return 13;
14668
14669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14671
14672
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14673
14674
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14675 return 14;
14676
14677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14679
14680
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14681
14682
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14683 return 15;
14684
14685
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14687
14688
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14689
14690
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14691 return 16;
14692
14693
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14695
14696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14697
14698
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14699 return 17;
14700
14701
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14703
14704
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14705
14706
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14707 return 18;
14708
14709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14710
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14711
14712
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14713
14714
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14715 return 19;
14716
14717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14719
14720
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14721
14722
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14723 return 20;
14724
14725
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14727
14728
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14729
14730
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14731 return 21;
14732
14733
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14735
14736
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14737
14738
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14739 return 22;
14740
14741
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14742
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14743
14744
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14745
14746
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14747 return 23;
14748
14749
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14751
14752
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14753
14754
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14755 return 24;
14756
14757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14759
14760
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14761
14762
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14763 return 25;
14764
14765
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14766
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14767
14768
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14769
14770
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14771 return 26;
14772
14773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14774
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14775
14776
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14777
14778
14779
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14780 {
14781 char const* kfname = filename;
14782 char keyfilename[2048]={0};
14783 zprint2("Writing key files for '%s'\n", kfname);
14784
14785 char temp_pw[QSTPWD_LEN] = {0};
14786 uint ind = 0;
14787 for(char const* ext : {"key","zpwd","zcheat"})
14788 {
14789 replace_extension(keyfilename, kfname, ext, 2047);
14790 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14791 char msg[80] = {0};
14792 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14793 msg[78]=13;
14794 msg[79]=10;
14795 pfwrite(msg, 80, fp);
14796 p_iputw(header.zelda_version,fp);
14797 p_putc(header.build,fp);
14798 char const* pwd = header.password;
14799 if(ind == 2) //.zcheat, hashed pwd
14800 {
14801 char hashmap = 'Z';
14802 hashmap += 'Q';
14803 hashmap += 'U';
14804 hashmap += 'E';
14805 hashmap += 'S';
14806 hashmap += 'T';
14807 for ( int q = 0; q < QSTPWD_LEN; ++q )
14808 {
14809 temp_pw[q] = header.password[q];
14810 temp_pw[q] += hashmap;
14811 }
14812 pwd = temp_pw;
14813 }
14814 pfwrite(pwd, strlen(pwd), fp);
14815 pack_fclose(fp);
14816 ++ind;
14817 }
14818 }
14819
14820 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14821 9 std::error_code ec;
14822
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14824 {
14825 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14826 return ec.value();
14827 }
14828
14829
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14830
14831 #ifdef __EMSCRIPTEN__
14832 em_sync_fs();
14833 #endif
14834
14835 9 return 0;
14836 9 }
14837
14838 // #ifdef _WIN32
14839 // static std::time_t to_time_t(FILETIME const& ft) {
14840 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14841 // t -= 116444736000000000ull;
14842 // t /= 10000000u;
14843 // return static_cast<std::time_t>(t);
14844 // }
14845 // #else
14846 // #endif
14847 template<typename TP>
14848 5 static std::time_t to_time_t(TP tp) {
14849 using namespace std::chrono;
14850 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14851 5 return system_clock::to_time_t(sctp);
14852 }
14853
14854 5 std::string get_time_last_modified_string(std::string path)
14855 {
14856
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14857 // TODO: C++20 but not supported yet.
14858 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14859 5 std::time_t tt = to_time_t(write_time);
14860 5 std::tm *gmt = std::gmtime(&tt);
14861 5 std::stringstream buffer;
14862
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14863
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14864 5 return formattedFileTime;
14865
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14866
14867 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14868 {
14869 // Always backup quest if it was last saved in a different version of the editor,
14870 // or if this a new file and is overwritting another qst file.
14871
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14872 {
14873 5 std::string backup_name;
14874
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14875
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14876 {
14877
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14878 5 }
14879 else
14880 {
14881 backup_name = fmt::format("{}", last_mod);
14882 }
14883
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14884
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14885
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14886 {
14887
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14888
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14889 {
14890
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14891 5 }
14892 else
14893 {
14894 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14895 }
14896 5 }
14897 5 }
14898
14899 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14900 9 fake_pack_writing = false;
14901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14902 {
14903 box_out("-- Error saving quest file! --");
14904 box_end(true);
14905 }
14906 9 else box_end(false);
14907 9 return ret;
14908 }
14909
14910 9 int32_t save_quest(const char *filename, bool timed_save)
14911 {
14912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14913
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14914 char ext1[5];
14915 9 ext1[0]=0;
14916
14917
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14918 {
14919 sprintf(ext1, "qt");
14920 }
14921 else
14922 {
14923 9 sprintf(ext1, "qb");
14924 }
14925
14926
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14927 {
14928 char backupname[2048];
14929 char backupname2[2048];
14930 char ext[12];
14931
14932 for(int32_t i=retention-1; i>0; --i)
14933 {
14934 sprintf(ext, "%s%d", ext1, i-1);
14935 replace_extension(backupname, filepath, ext, 2047);
14936
14937 if(exists(backupname))
14938 {
14939 sprintf(ext, "%s%d", ext1, i);
14940 replace_extension(backupname2, filepath, ext, 2047);
14941
14942 if(exists(backupname2))
14943 {
14944 remove(backupname2);
14945 }
14946
14947 rename(backupname, backupname2);
14948 }
14949 }
14950
14951 //don't do this if we're not saving to the same name -DD
14952 if(!timed_save && !strcmp(filepath, filename))
14953 {
14954 sprintf(ext, "%s%d", ext1, 0);
14955 replace_extension(backupname, filepath, ext, 2047);
14956 rename(filepath, backupname);
14957 }
14958 }
14959
14960 int32_t ret;
14961 9 ret = save_unencoded_quest(filename, compress, filename);
14962
14963 9 return ret;
14964 }
14965
14966 8 void center_zq_class_dialogs()
14967 {
14968 8 jwin_center_dialog(pwd_dlg);
14969 8 }
14970
14971 void zmap::prv_secrets(bool high16only)
14972 {
14973 mapscr *s = &prvscr;
14974 mapscr *t = prvlayers;
14975 int32_t ft=0;
14976
14977 for(int32_t i=0; i<176; i++)
14978 {
14979 if(!high16only)
14980 {
14981 for(int32_t j=-1; j<6; j++)
14982 {
14983 int32_t newflag = -1;
14984
14985 for(int32_t iter=0; iter<2; ++iter)
14986 {
14987 if(!t[j].valid)
14988 continue;
14989
14990 int32_t checkflag=combobuf[t[j].data[i]].flag;
14991
14992 if(iter==1)
14993 {
14994 checkflag=t[j].sflag[i];
14995 }
14996
14997 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14998 if (ft != -1)
14999 {
15000 if(j==-1)
15001 {
15002 s->data[i] = s->secretcombo[ft];
15003 s->cset[i] = s->secretcset[ft];
15004 newflag = s->secretflag[ft];
15005 }
15006 else
15007 {
15008 t[j].data[i] = t[j].secretcombo[ft];
15009 t[j].cset[i] = t[j].secretcset[ft];
15010 newflag = t[j].secretflag[ft];
15011 }
15012 }
15013 }
15014
15015 if(newflag >-1)
15016 {
15017 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15018 }
15019 }
15020 }
15021
15022 //if(true)
15023 //{
15024 int32_t newflag = -1;
15025
15026 for(int32_t iter=0; iter<2; ++iter)
15027 {
15028 int32_t checkflag=combobuf[s->data[i]].flag;
15029
15030 if(iter==1)
15031 {
15032 checkflag=s->sflag[i];
15033 }
15034
15035 if((checkflag > 15)&&(checkflag < 32))
15036 {
15037 s->data[i] = s->secretcombo[(checkflag)-16+4];
15038 s->cset[i] = s->secretcset[(checkflag)-16+4];
15039 newflag = s->secretflag[(checkflag)-16+4];
15040 // putit = true;
15041 }
15042 }
15043
15044 if(newflag >-1) s->sflag[i] = newflag;
15045
15046 for(int32_t j=0; j<6; j++)
15047 {
15048 if(!t[j].valid) continue;
15049
15050 int32_t newflag2 = -1;
15051
15052 for(int32_t iter=0; iter<2; ++iter)
15053 {
15054 int32_t checkflag=combobuf[t[j].data[i]].flag;
15055
15056 if(iter==1)
15057 {
15058 checkflag=t[j].sflag[i];
15059 }
15060
15061 if((checkflag > 15)&&(checkflag < 32))
15062 {
15063 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15064 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15065 newflag2 = t[j].secretflag[(checkflag)-16+4];
15066 }
15067 }
15068
15069 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15070 }
15071 }
15072
15073 //FFCs
15074 word num_ffcs = s->numFFC();
15075 for(word i=0; i<num_ffcs; ++i)
15076 {
15077 if(!high16only)
15078 {
15079 for(int32_t iter=0; iter<1; ++iter)
15080 {
15081 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15082
15083 if(iter==1)
15084 {
15085 checkflag=s->sflag[i];
15086 }
15087
15088 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15089 if (ft != -1)
15090 {
15091 s->ffcs[i].data = s->secretcombo[ft];
15092 s->ffcs[i].cset = s->secretcset[ft];
15093 }
15094 }
15095 }
15096
15097 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15098 {
15099 for(int32_t iter=0; iter<1; ++iter)
15100 {
15101 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15102
15103 if(iter==1)
15104 {
15105 // FFCs can't have flags! Yet...
15106 }
15107
15108 if((checkflag > 15)&&(checkflag < 32))
15109 {
15110 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15111 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15112 }
15113 }
15114 }
15115 }
15116 }
15117